Example #1
0
 /**
  * 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 aggreagated 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> objets 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 coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aItem !== null) {
             if (!$this->aItem->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aItem->getValidationFailures());
             }
         }
         if ($this->aUser !== null) {
             if (!$this->aUser->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aUser->getValidationFailures());
             }
         }
         if (($retval = ShoppingCartPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
 /**
  * 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 aggreagated 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> objets 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 coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aEmpresa !== null) {
             if (!$this->aEmpresa->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aEmpresa->getValidationFailures());
             }
         }
         if ($this->aItem !== null) {
             if (!$this->aItem->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aItem->getValidationFailures());
             }
         }
         if (($retval = DocumentoPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         if ($this->collHistoricoDocumentos !== null) {
             foreach ($this->collHistoricoDocumentos as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
Example #3
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $item = new Item();
     $detil_item = new DetilItem();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Item'], $_POST['DetilItem'])) {
         $item->attributes = $_POST['Item'];
         $detil_item->attributes = $_POST['DetilItem'];
         if ($item->validate() & $detil_item->validate()) {
             $connection = Yii::app()->db;
             $transaction = $connection->beginTransaction();
             try {
                 if ($item->save()) {
                     $detil_item->setAttribute('ID_ITEM', $item->ID_ITEM);
                     $detil_item->setAttribute('TANGGAL_INPUT', date('Y-m-d H:i:s'));
                     if ($detil_item->save()) {
                         $transaction->commit();
                         Yii::app()->user->setFlash('info', MyFormatter::alertSuccess('<strong>Selamat!</strong> Data telah berhasil disimpan.'));
                         $this->redirect(array('view', 'id' => $item->ID_ITEM));
                     }
                 }
             } catch (Exception $e) {
                 $transaction->rollback();
                 Yii::app()->user->setFlash('info', MyFormatter::alertDanger('<strong>Error!</strong> Data gagal untuk disimpan.' . $e->getMessage()));
             }
         }
     }
     $this->render('create', array('item' => $item, 'detil_item' => $detil_item));
 }
 public function actionCreateImage($grid_cart = 'N')
 {
     $model = new Item();
     $price_tiers = PriceTier::model()->getListPriceTier();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (Yii::app()->user->checkAccess('item.create')) {
         if (isset($_POST['Item'])) {
             $model->attributes = $_POST['Item'];
             $qty = isset($_POST['Item']['quantity']) ? $_POST['Item']['quantity'] : 0;
             $unit_price = isset($_POST['Item']['unit_price']) ? $_POST['Item']['unit_price'] : 0;
             $model->quantity = $qty;
             $model->unit_price = $unit_price;
             $category_name = $_POST['Item']['category_id'];
             $publisher_name = $_POST['Item']['publisher_id'];
             $author_name = $_POST['Item']['author_id'];
             $publisher_id = Publisher::model()->savePublisher($publisher_name);
             if ($publisher_id !== null) {
                 $model->publisher_id = $publisher_id;
             }
             $author_id = Author::model()->saveAuthor($author_name);
             if ($author_id !== null) {
                 $model->author_id = $author_id;
             }
             //Saving new category to `category` table
             $category_id = Category::model()->saveCategory($category_name);
             if ($category_id !== null) {
                 $model->category_id = $category_id;
             }
             if ($model->validate()) {
                 $transaction = Yii::app()->db->beginTransaction();
                 try {
                     if ($model->save()) {
                         if (isset($_POST['Item']['count_interval'])) {
                             Item::model()->saveItemCounSchedule($model->id);
                         }
                         // Saving Item Price Tier to `item_price_tier`
                         ItemPriceTier::model()->saveItemPriceTier($model->id, $price_tiers);
                         $this->addImages($model, $transaction);
                         $transaction->commit();
                         if ($grid_cart == 'N') {
                             Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, 'Item : <strong>' . $model->name . '</strong> have been saved successfully!');
                             $this->redirect(array('createImage'));
                         } elseif ($grid_cart == 'S') {
                             Yii::app()->wshoppingCart->addItem($model->id);
                             $this->redirect(array('wholeSale/index'));
                         } elseif ($grid_cart == 'R') {
                             Yii::app()->receivingCart->addItem($model->id);
                             $this->redirect(array('receivingItem/index'));
                         }
                     }
                 } catch (Exception $e) {
                     $transaction->rollback();
                     //print_r($e);
                     Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_WARNING, 'Oop something wrong : <strong>' . $e);
                 }
             }
         }
     } else {
         //throw new CHttpException(403, 'You are not authorized to perform this action');
         $this->redirect(array('site/ErrorException', 'err_no' => 403));
     }
     if (Yii::app()->request->isAjaxRequest) {
         $cs = Yii::app()->clientScript;
         $cs->scriptMap = array('jquery.js' => false, 'bootstrap.js' => false, 'jquery.min.js' => false, 'bootstrap.min.js' => false, 'bootstrap.notify.js' => false, 'bootstrap.bootbox.min.js' => false);
         //Yii::app()->clientScript->scriptMap['*.js'] = false;
         echo CJSON::encode(array('status' => 'render', 'div' => $this->renderPartial('_form_image', array('model' => $model, 'price_tiers' => $price_tiers), true, true)));
         Yii::app()->end();
     } else {
         $this->render('create_image', array('model' => $model, 'price_tiers' => $price_tiers));
     }
 }
Example #5
0
 function manageEntries()
 {
     // Delete entries in bulk
     if ($_POST['action'] == 'delete' && count($_POST['entry_check']) > 0) {
         if ($this->delete('entry')) {
             $this->showList("Portfolio entries successfully deleted");
             return;
         }
     }
     // If an individual entry is specified, edit it (and/or validate and process it)
     // Otherwise, just show the full list
     if (empty($_GET['entry'])) {
         $this->showList();
     } else {
         $itemID = intval($_GET['entry']);
         if (isset($_POST['submit_check'])) {
             // If the form was submitted...
             $item = new Item($_POST);
             if ($form_errors = $item->validate()) {
                 $this->editIndividual($itemID, $form_errors);
             } else {
                 $item->process();
             }
         } else {
             $this->editIndividual($itemID);
             // If not, just edit the entry
         }
     }
 }
Example #6
0
 /**
  * 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 aggreagated 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> objets 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 coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aBook !== null) {
             if (!$this->aBook->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aBook->getValidationFailures());
             }
         }
         if ($this->aItemRelatedByPackageId !== null) {
             if (!$this->aItemRelatedByPackageId->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aItemRelatedByPackageId->getValidationFailures());
             }
         }
         if (($retval = ItemPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         if ($this->collItemsRelatedById !== null) {
             foreach ($this->collItemsRelatedById as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collSectionHasItems !== null) {
             foreach ($this->collSectionHasItems as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
 public function saveOrder()
 {
     $inputShipFrom = Input::get('shipFrom');
     $inputShipFrom = $this->jsonToInputArray($inputShipFrom);
     $inputshipTo = Input::get('shipTo');
     $inputshipTo = $this->jsonToInputArray($inputshipTo);
     $inputItem = Input::get('itemDetail');
     $inputItem = $this->jsonToInputArray($inputItem);
     $inputCompany = Input::get('companyInfo');
     $inputCompany = $this->jsonToInputArray($inputCompany);
     $result = array('errors' => '', 'result' => '');
     $foundErrors = false;
     //validate ship from info.
     $shipFrom = new ShipFrom();
     if ($shipFrom->validate($inputShipFrom) === false) {
         $foundErrors = true;
         $messages = $shipFrom->messages();
         if (count($messages)) {
             foreach ($messages as $message) {
                 $result['errors'] .= "<li>{$message}</li>";
             }
         }
     }
     //validate ship to information
     $shipTo = new ShipTo();
     if ($shipTo->validate($inputshipTo) === false) {
         $foundErrors = true;
         $messages = $shipTo->messages();
         if (count($messages)) {
             foreach ($messages as $message) {
                 $result['errors'] .= "<li>{$message}</li>";
             }
         }
     }
     //validate item information
     $item = new Item();
     if ($item->validate($inputItem) === false) {
         $foundErrors = true;
         $messages = $item->messages();
         if (count($messages)) {
             foreach ($messages as $message) {
                 $result['errors'] .= "<li>{$message}</li>";
             }
         }
     }
     //validate company information
     $company = new Company();
     if ($company->validate($inputCompany) === false) {
         $foundErrors = true;
         $messages = $company->messages();
         if (count($messages)) {
             foreach ($messages as $message) {
                 $result['errors'] .= "<li>{$message}</li>";
             }
         }
     }
     if ($foundErrors == true) {
         echo json_encode($result);
         return;
     }
     $data = array('shipFrom' => $inputShipFrom, 'shipTo' => $inputshipTo, 'item' => $inputItem, 'company' => $inputCompany);
     $action = Input::get('action');
     if ($action == 'update') {
         $orderId = Input::get('order_id');
         if (Order::update($orderId, $data) == true) {
             $result['result'] = 'success';
         } else {
             $result['errors'] = "<li>There was a problem with record update.Please try later.</li>";
         }
     } else {
         //create new order
         $newOrderId = Order::insert($data);
         if (is_numeric($newOrderId) && $newOrderId > 0) {
             $result['result'] = 'success';
         }
     }
     echo json_encode($result);
 }
Example #8
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Item('create');
     $img = new ItemImg('create');
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $action = 'item';
     if (isset($_POST['Item'])) {
         $model->attributes = $_POST['Item'];
         $model->sn = 'YC' . date('Ymd') . mt_rand(10000, 99999);
         if ($_POST['Item']['props']) {
             foreach ($_POST['Item']['props'] as $key => $value) {
                 $p = ItemProp::model()->findByPk($key);
                 if ($p->type == 'multiCheck') {
                     $values = implode($value, ',');
                     $p_arr[] = $key . ':' . $values;
                     foreach ($value as $kk => $vv) {
                         $v = PropValue::model()->findByPk($vv);
                         $value_name[] = $v->value_name;
                     }
                     $value_names = implode($value_name, ',');
                     $v_arr[] = $p->prop_name . ':' . $value_names;
                 } elseif ($p->type == 'optional') {
                     $p_arr[] = $key . ':' . $value;
                     $v = PropValue::model()->findByPk($value);
                     $v_arr[] = $p->prop_name . ':' . $v->value_name;
                 } elseif ($p->type == 'input') {
                     //如果是文本框输入的话 不纳入搜索
                     //也就不纳入到props里 只保存到prop_names里
                     $p_arr[] = $key . ':' . $value;
                     $v_arr[] = $p->prop_name . ':' . $value;
                 }
             }
             $props = implode($p_arr, ';');
             $model->props = $props;
             $props_name = implode($v_arr, ';');
             $model->props_name = $props_name;
         }
         if ($model->validate() && $img->validate()) {
             //                print_r($_POST);
             //                exit;
             if ($model->save()) {
                 if ($_POST['ItemImg']) {
                     for ($i = 0; $i <= 4; $i++) {
                         $img->isNewRecord = true;
                         $img->attributes = $_POST['ItemImg'];
                         $img->item_id = $model->item_id;
                         $img->position = $i;
                         $img->create_time = time();
                         // file handling
                         $imageUploadFile = CUploadedFile::getInstance($img, 'url' . $i);
                         if ($imageUploadFile !== null) {
                             // only do if file is really uploaded
                             $imageFileExt = $imageUploadFile->extensionName;
                             $save_path = dirname(Yii::app()->basePath) . '/upload/' . $action . '/image/';
                             if (!file_exists($save_path)) {
                                 mkdir($save_path, 0777, true);
                             }
                             $ymd = date("Ymd");
                             $save_path .= $ymd . '/';
                             if (!file_exists($save_path)) {
                                 mkdir($save_path, 0777, true);
                             }
                             $img_prefix = date("YmdHis") . '_' . rand(10000, 99999);
                             $imageFileName = $img_prefix . '.' . $imageFileExt;
                             $img->url = $ymd . '/' . $imageFileName;
                             $save_path .= $imageFileName;
                             $img->save();
                             $imageUploadFile->saveAs($save_path);
                         }
                     }
                 }
                 $this->redirect(array('view', 'id' => $model->item_id));
             }
         }
     }
     $this->render('create', array('model' => $model, 'img' => $img));
 }
Example #9
0
 /**
  * If item object is given then updates it else inserts a new item
  * object in the database
  * @param object $item (Optional)
  * @return array
  */
 protected function _saveItem($item = null)
 {
     if (!$item) {
         $item = new Item(array());
     }
     $item->name = RequestMethods::post("name");
     $item->description = RequestMethods::post("description");
     $item->price = RequestMethods::post("price");
     $item->tax = RequestMethods::post("tax", 0.0);
     $item->user_id = $this->user->id;
     $item->period = RequestMethods::post("period", 30);
     if ($item->validate()) {
         $item->save();
         return array("success" => true, "item" => $item);
     }
     return array("success" => false, "errors" => $item->errors);
 }
Example #10
0
 protected function _saveTests($package, $sorted)
 {
     $items = RequestMethods::post("items", array());
     $i = array();
     foreach ($items as $key => $value) {
         $i[$value] = $value;
     }
     $found = array_diff_key($sorted, $i);
     foreach ($found as $f) {
         unset($sorted[$f->test_id]);
         $f->delete();
     }
     $save = array_diff_key($i, $sorted);
     foreach ($save as $key => $value) {
         $item = new Item(array("package_id" => $package->id, "test_id" => $value, "organization_id" => $this->organization->id));
         if ($item->validate()) {
             $item->save();
             $sorted[$item->test_id] = $item;
         }
     }
     return $sorted;
 }