/**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Attributes the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Attributes::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Beispiel #2
0
    ?>
                        </div>
            <?php 
}
?>
            </ul>
            </div>
                </div>
                </div>
                <div id="description">
                    <div class="profileDescriptionBlock">
              <?php 
$criteria = new CDbCriteria();
$criteria->condition = 'Type IN ("textarea","textfield") AND Status=1';
$criteria->order = 'Position ASC';
$attributes = Attributes::model()->findAll($criteria);
if ($attributes) {
    foreach ($attributes as $att_list) {
        $description = $selectValue['basic'][$att_list->Objid];
        echo $value = '';
        ?>
                <div class="profileDesciption">
                <label><?php 
        echo $att_list->Name;
        ?>
</label> 
                <span>
                <?php 
        if ($att_list->Type == 'textfield') {
            echo $form->textField($options_list, 'AttributeValueId[' . $att_list->Objid . ']', array('value' => $description));
        } else {
Beispiel #3
0
 public function actionSaveProduct()
 {
     $product = Products::model()->findByPk($_POST['productId']);
     $attributes = json_decode($_POST['attributes']);
     //удмлим все значения, связанные с текущим атрибутом и сам атрибут
     $attributes_AR = Attributes::model()->findAll("product_id=:product_id", array(':product_id' => $_POST['productId']));
     foreach ($attributes_AR as $attribute) {
         Values::model()->deleteAll("attribute_id=:attribute_id", array(':attribute_id' => $attribute->id));
         $attribute->delete();
     }
     foreach ($attributes as $attribute) {
         $attribute_AR = new Attributes();
         $attribute_AR->product_id = $product->id;
         $attribute_AR->name = $attribute->name;
         $res = $attribute_AR->save();
         if ($res == false) {
             echo "false-attr";
             return;
         }
         foreach ($attribute->values as $value) {
             $value_AR = new Values();
             $value_AR->name = $value->name;
             $value_AR->add_price = $value->add_price;
             $value_AR->attribute_id = $attribute_AR->id;
             $res = $value_AR->save();
             if ($res == false) {
                 echo "false-value";
                 return;
             }
         }
     }
     $product->discount = $_POST['discount'];
     $product->name = $_POST['name'];
     $product->text = $_POST['text'];
     if ($_POST['photo'] != '') {
         $product->photo = $_POST['photo'];
     }
     $product->main_price = $_POST['main_price'];
     $product->sostav = $_POST['sostav'];
     $res = $product->update();
     if ($res == false) {
         var_dump($product->errors);
         echo "false-prod";
         return;
     }
     echo "true";
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $options_list = new UserOptions();
     $options_text = new UserText();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Users']) || isset($_POST['UserText']) || isset($_POST['UserOptions'])) {
         if (isset($_POST['Users'])) {
             $model->attributes = $_POST['Users'];
             $model->save();
         }
         if (isset($_POST['UserText'])) {
             $options_text->attributes = $_POST['UserText'];
             foreach ($options_text->Value as $key => $data) {
                 if (UserText::model()->findByAttributes(array('UserId' => $id, 'AttributeId' => $key))) {
                     $res = UserText::model()->findByAttributes(array('UserId' => $id, 'AttributeId' => $key));
                     if ($data) {
                         $res->Value = $data;
                         $res->save();
                     } else {
                         $res->delete();
                     }
                 } else {
                     if ($data) {
                         $options_text = new UserText();
                         $options_text->UserId = $id;
                         $options_text->AttributeId = $key;
                         $options_text->Value = $data;
                         $options_text->save();
                     }
                 }
             }
         }
         if (isset($_POST['UserOptions'])) {
             $options_list->attributes = $_POST['UserOptions'];
             $result = $options_list->AttributeValueId;
             foreach ($result as $key => $data) {
                 if (Attributes::model()->findByPk($key)->Type == 'checkbox') {
                     if (!empty($data)) {
                         $existed = array();
                         if (UserOptions::model()->findAllByAttributes(array('UserId' => $id, 'AttributeId' => $key))) {
                             $res = UserOptions::model()->findAllByAttributes(array('UserId' => $id, 'AttributeId' => $key));
                             foreach ($res as $val) {
                                 $existed[] = $val->AttributeValueId;
                             }
                         }
                         $toInsert = array_diff($data, $existed);
                         $toDelete = array_diff($existed, $data);
                         if (!empty($toInsert)) {
                             foreach ($toInsert as $insert) {
                                 $options_list = new UserOptions();
                                 $options_list->UserId = $id;
                                 $options_list->AttributeId = $key;
                                 $options_list->AttributeValueId = $insert;
                                 $options_list->save();
                             }
                         }
                         if (!empty($toDelete)) {
                             foreach ($toDelete as $delete) {
                                 UserOptions::model()->findByAttributes(array('UserId' => $id, 'AttributeId' => $key, 'AttributeValueId' => $delete))->delete();
                             }
                         }
                     } else {
                         if (UserOptions::model()->findAllByAttributes(array('UserId' => $id, 'AttributeId' => $key))) {
                             UserOptions::model()->deleteAllByAttributes(array('UserId' => $id, 'AttributeId' => $key));
                         }
                     }
                 } else {
                     if (UserOptions::model()->findByAttributes(array('UserId' => $id, 'AttributeId' => $key))) {
                         $res = UserOptions::model()->findByAttributes(array('UserId' => $id, 'AttributeId' => $key));
                         if ($data) {
                             $res->AttributeValueId = $data;
                             $res->save();
                         } else {
                             $res->delete();
                         }
                     } else {
                         $options_list = new UserOptions();
                         $options_list->UserId = $id;
                         $options_list->AttributeId = $key;
                         $options_list->AttributeValueId = $data;
                         $options_list->save();
                     }
                 }
             }
         }
         $this->redirect(array('update', 'id' => $model->Objid));
     }
     $this->render('update', array('model' => $model, 'options_list' => $options_list, 'options_text' => $options_text));
 }
Beispiel #5
0
?>
		<?php 
echo $form->error($model, 'Role');
?>
	</div>
	<div class="row buttons">
		<?php 
echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('class' => 'btn btn-inverse'));
?>
	</div>
   </div>
   </div>
    <div id="basic" class="tab-pane">
    <div class="twoColumns">   
   <?php 
$attributes = Attributes::model()->findAll('Status=1');
foreach ($attributes as $att_list) {
    ?>
   <div class="row" id="userOptions">
    <label><?php 
    echo $att_list->Name;
    ?>
</label>
    <?php 
    $value = '';
    if (UserText::model()->findByAttributes(array('UserId' => $model->Objid, 'AttributeId' => $att_list->Objid))) {
        $value = UserText::model()->findByAttributes(array('UserId' => $model->Objid, 'AttributeId' => $att_list->Objid))->Value;
    }
    if ($att_list->Type == 'textfield') {
        echo $form->textField($options_text, 'Value[' . $att_list->Objid . ']', array('value' => $value));
    } else {