Пример #1
0
 /**
  * Creates a new model.
  *
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @param bool $quick If true, this indicates the action is being requested via AJAX
  */
 public function actionCreate($quick = false, $duplicate = false)
 {
     $model = new Quote();
     if ($duplicate && !isset($_POST['Quote'])) {
         $copiedModel = Quote::model()->findByPk($duplicate);
         if (!empty($copiedModel)) {
             foreach ($copiedModel->attributes as $name => $value) {
                 if ($name != 'id') {
                     $model->{$name} = $value;
                 }
             }
             $model->setLineItems($this->duplicateLineItems($copiedModel), false, true);
         }
     }
     $users = User::getNames();
     if ($quick && !Yii::app()->request->isAjaxRequest) {
         throw new CHttpException(400);
     }
     $currency = Yii::app()->params->currency;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Quote'])) {
         $model->setX2Fields($_POST['Quote']);
         $model->currency = $currency;
         $model->createDate = time();
         $model->lastUpdated = $model->createDate;
         $model->createdBy = Yii::app()->user->name;
         $model->updatedBy = $model->createdBy;
         if (empty($model->name)) {
             $model->name = '';
         }
         if (isset($_POST['lineitem'])) {
             $model->lineItems = $_POST['lineitem'];
         }
         if (!$model->hasLineItemErrors) {
             if ($model->save()) {
                 $model->createEventRecord();
                 $model->createActionRecord();
                 $model->saveLineItems();
                 if (!$quick) {
                     $this->redirect(array('view', 'id' => $model->id));
                 } else {
                     if (isset($_GET['recordId']) && isset($_GET['recordType'])) {
                         $recordId = $_GET['recordId'];
                         $recordType = $_GET['recordType'];
                         $relatedModel = X2Model::model($_GET['recordType'])->findByPk($recordId);
                         // tie record to quote
                         if ($relatedModel) {
                             $relate = new Relationships();
                             $relate->firstId = $model->id;
                             $relate->firstType = "Quote";
                             $relate->secondId = $relatedModel->id;
                             $relate->secondType = $recordType;
                             $relate->save();
                             $model->createAssociatedAction(X2Model::getAssociationType(get_class($relatedModel)), $relatedModel->id);
                         }
                     }
                     return;
                 }
             }
         }
     }
     // get products
     $products = Product::activeProducts();
     $viewData = array('model' => $model, 'users' => $users, 'products' => $products, 'quick' => $quick);
     if (!$quick) {
         $this->render('create', $viewData);
     } else {
         if ($model->hasErrors() || $model->hasLineItemErrors) {
             // Sneak into the response that validation failed via setting
             // the response code manually:
             header('HTTP/1.1 400 Validation Error');
         }
         $this->renderPartial('create', $viewData, false, true);
     }
 }
Пример #2
0
 * 02110-1301 USA.
 * 
 * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
 * California 95067, USA. or at email address contact@x2engine.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * X2Engine" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by X2Engine".
 *****************************************************************************************/
$submitButton = isset($submitButton) ? $submitButton : true;
$htmlOptions = !isset($htmlOptions) ? array() : $htmlOptions;
$form = $this->beginWidget('ProductsActiveForm', array('formModel' => $model, 'htmlOptions' => $htmlOptions));
echo $form->textArea($model, 'actionDescription');
$dummyQuote = new Quote();
if (is_array($model->lineitem)) {
    $dummyQuote->setLineItems($model->lineitem);
}
Yii::app()->controller->renderPartial('application.modules.quotes.views.quotes._lineItems', array('model' => $dummyQuote, 'readOnly' => false, 'module' => Yii::app()->getModule('quotes'), 'products' => Product::activeProducts(), 'namespacePrefix' => $form->namespace, 'saveButtonId' => 'save-publisher', 'modelName' => get_class($model), 'mini' => true));
echo $form->hiddenField($model, 'associationType');
echo $form->hiddenField($model, 'associationId');
echo $form->hiddenField($model, 'assignedTo');
if ($submitButton) {
    echo $form->submitButton();
}
$this->endWidget();