/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Document();
     $path = Yii::app()->basePath . '/../uploads/documents';
     if (!is_dir($path)) {
         mkdir($path);
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Document'])) {
         $model->attributes = $_POST['Document'];
         if ($model->validate()) {
             //Document upload script
             if (@(!empty($_FILES['Document']['name']['doc_file']))) {
                 $model->doc_file = $_POST['Document']['doc_file'];
                 if ($model->validate(array('doc_file'))) {
                     $model->doc_file = CUploadedFile::getInstance($model, 'doc_file');
                 } else {
                     $model->doc_file = '';
                 }
                 $model->doc_file->saveAs($path . '/' . time() . '_' . str_replace(' ', '_', strtolower($model->doc_file)));
                 $model->doc_type = $model->doc_file->getType();
                 $model->doc_size = $model->doc_file->getSize();
                 $model->doc_file = time() . '_' . str_replace(' ', '_', strtolower($model->doc_file));
             }
             $model->created_on = new CDbExpression('NOW()');
             $model->created_by = Yii::app()->user->id;
             if ($model->save()) {
                 Yii::app()->user->setFlash('success', 'Document created successfully');
                 $this->redirect(array('view', 'id' => $model->id));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * [addSalesman Add a new salesman from the list]
  * @method addSalesman
  * @param  [string] $cpf    [CPF document]
  * @param  [string] $name   [Salesman name]
  * @param  [string] $salary [Salary]
  */
 public function addSalesman($cpf, $name, $salary)
 {
     try {
         if (!Document::validate($cpf)) {
             throw new Exception('Invalid CPF document');
         }
         $objSalesman = new stdClass();
         $objSalesman->cpf = $cpf;
         $objSalesman->name = trim($name);
         $objSalesman->salary = (double) str_replace(' ', '', $salary);
         $objSalesman->total_sales = 0;
         array_push($this->arrSellers, $objSalesman);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
 /**
  * [addConsumer Add a new consumer from the list]
  * @method addConsumer
  * @param  [number] $cnpj [Document consumer]
  * @param  [string] $name [Consumer name]
  * @param  [string] $business_area [Consumer business area]
  */
 public function addConsumer($cnpj, $name, $business_area)
 {
     try {
         if (!Document::validate($cnpj)) {
             throw new Exception('Invalid CNPJ document');
         }
         $objConsumer = new stdClass();
         $objConsumer->cnpj = $cnpj;
         $objConsumer->name = $name;
         $objConsumer->business_area = $business_area;
         $objConsumer->total_sales = 0;
         array_push($this->arrConsumers, $objConsumer);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
 /**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggregated array of ValidationFailed objects will be returned.
  *
  * @param array $columns Array of column names to validate.
  * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objects otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aJournalEntry !== null) {
             if (!$this->aJournalEntry->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aJournalEntry->getValidationFailures());
             }
         }
         if ($this->aDocument !== null) {
             if (!$this->aDocument->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aDocument->getValidationFailures());
             }
         }
         if ($this->aUserRelatedByCreatedBy !== null) {
             if (!$this->aUserRelatedByCreatedBy->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aUserRelatedByCreatedBy->getValidationFailures());
             }
         }
         if ($this->aUserRelatedByUpdatedBy !== null) {
             if (!$this->aUserRelatedByUpdatedBy->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aUserRelatedByUpdatedBy->getValidationFailures());
             }
         }
         if (($retval = JournalEntryImagePeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
 public function actionCreate()
 {
     $this->forcePostRequest();
     $_POST = Yii::app()->input->stripClean($_POST);
     $poll = new Document();
     $poll->content->populateByForm();
     $poll->name = Yii::app()->request->getParam('name');
     $poll->body = Yii::app()->request->getParam('body');
     $poll->folder_id = (int) Yii::app()->request->getParam('selectFolder');
     //$poll->allow_multiple = Yii::app()->request->getParam('allowMultiple');
     if ($poll->validate()) {
         $poll->save();
         $this->renderJson(array('wallEntryId' => $poll->content->getFirstWallEntryId()));
     } else {
         $this->renderJson(array('errors' => $poll->getErrors()), false);
     }
 }