Exemplo n.º 1
0
 public function __construct($category_name, $written_language_tag)
 {
     $language_model = new LanguageModel();
     $this->written_language_id = $language_model->getWrittenLanguageIdByTag($written_language_tag);
     $product_db_class_name = StrLib::underlineToClassName($category_name) . 'Db';
     $product_attribute_value_wlp_db_class_name = StrLib::underlineToClassName($category_name) . 'AttributeValueWlpDb';
     $this->product_db = new $product_db_class_name();
     $this->product_attribute_value_wlp_db = new $product_attribute_value_wlp_db_class_name();
 }
Exemplo n.º 2
0
 /**
  * Get the languages by the users id
  *
  * @param integer $iUserID
  * @return array
  */
 function getUserLanguages($iUserID)
 {
     $oUserLang = new UserLanguageModel();
     $oLang = new LanguageModel();
     $aUserLanguages = $oUserLang->getList('user_id = ' . $this->quote($iUserID));
     foreach ($aUserLanguages as $key => $aUserLang) {
         $aLang = $oLang->getList('id = ' . $this->quote($aUserLang['lang_id']));
         if (count($aLang) > 0) {
             $aUserLang['name'] = $aLang[0]['name'];
         }
         $aUserLanguages[$key] = $aUserLang;
     }
     return $aUserLanguages;
 }
Exemplo n.º 3
0
    /**
     * 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);
        $messageModels = LanguageModel::model()->getAllLanguageModels($id);

        if (isset($_POST['SourceMessageModel'])) {
            $model->attributes = $_POST['SourceMessageModel'];
            if ($_POST['MessageModel']) {
                foreach ($_POST['MessageModel'] as $key => $value) {
                    if (!empty($value['translation'])) {
                        $messageModel = MessageModel::model()->findByAttributes(array('id' => $model->id, 'language' => $key));
                        if ($messageModel == null) {
                            $messageModel = new MessageModel;
                            $messageModel->language = $key;
                            $messageModel->id = $model->id;
                            $messageModel->setIsNewRecord(true);
                        } else {
                            $messageModel->setIsNewRecord(false);
                        }
                       // die($messageModel->isNewRecord);
                        $messageModel->attributes = $value;
                        $messageModel->save(false);
                    }
                }
            }
            if ($model->save())
                $this->redirect(array('index'));
        }

        $this->render('update', array(
            'model' => $model,
            'messageModels' => $messageModels,
        ));
    }
Exemplo n.º 4
0
 public function beforeAction($action)
 {
     $this->language_id = LanguageModel::getLanguageIdByCode(Yii::app()->language);
     if (isset($_POST['dropUpload']) && $_POST['dropUpload'] == 1) {
         $this->handleUploads();
     }
     return true;
 }
Exemplo n.º 5
0
 /**
  * @return array relational rules.
  */
 public function relations()
 {
     // NOTE: you may need to adjust the relation name and the related
     // class name for the relations automatically generated below.
     return array(
         'value_description' => array(self::HAS_ONE, 'ValueDescription', 'value_id',
             'condition' => 'value_description.language_id = ' . LanguageModel::getLanguageIdByCode(Yii::app()->language)),
     );
 }
Exemplo n.º 6
0
 function getLanguages()
 {
     $langs = LanguageModel::all();
     $result = array();
     foreach ($langs as $lang) {
         $result[] = Activerecord::createArrayFromModel($lang);
     }
     return $result;
 }
Exemplo n.º 7
0
 /**
  * Load available languages.
  * @return LanguageModel collection
  */
 private function loadLanguages()
 {
     $model = LanguageModel::model()->cache(Yii::app()->controller->cacheTime)->findAll();
     foreach ($model as $lang) {
         $this->_languages[$lang->code] = $lang;
         if ($lang->default === '1') {
             $this->_default = $lang->code;
         }
     }
     return $this->_languages;
 }
Exemplo n.º 8
0
 /**
  * @return array relational rules.
  */
 public function relations()
 {
     // NOTE: you may need to adjust the relation name and the related
     // class name for the relations automatically generated below.
     return array(
         'variation_description' => array(self::HAS_ONE, 'VariationDescription', 'variation_id',
             'condition' => 'variation_description.language_id = ' . LanguageModel::getLanguageIdByCode(Yii::app()->language)),
         'attributes' => array(self::MANY_MANY, 'Attribute', 'variation2attribute(attribute_id, variation_id)',
             'condition' => 'attributes.status = 1'),
     );
 }
Exemplo n.º 9
0
    public function actionUpdate($id)
    {
        $model = $this->loadModel($id);
        $lang_model = new LanguageModel;
        $CadDescModel = new CategoryDescription;
        $aLangNames = array();
        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);


        $allLangs = $lang_model->findAll('1', array('order' => 'id ASC'));

        $aCategories = Category::model()->generateTreeList();
        
        $aCatNames = $CadDescModel->findAll("category_id = '" . $id . "'");
        foreach ($aCatNames as $lng_category) {
            $aLangNames[$lng_category['language_id']] = $lng_category['category_name'];
        }

        if (isset($_POST['Category'])) {
            $model->parent_id = $_POST['Category']['parent_id'];
            $model->sort_order = $_POST['Category']['sort_order'];

            if ($model->save()) {
                foreach ($_POST['CategoryDescription']['category_name'] as $langId => $catName) {
                    $cat_desc_model = new CategoryDescription;
                    $cat_desc_model->updateByPk(array('category_id' => $id, 'language_id' => $langId), array('category_name' => $catName));
                }
                $this->redirect(array('category/index'));

            }
        }

        $this->render('update', array(
            'model' => $model,
            'allLangs' => $allLangs,
            'CadDescModel' => $CadDescModel,
            'aLangNames' => $aLangNames,
            'aCategories' => $aCategories,
        ));
    }
Exemplo n.º 10
0
 /**
  * @return array relational rules.
  */
 public function relations()
 {
     // NOTE: you may need to adjust the relation name and the related
     // class name for the relations automatically generated below.
     return array(
         'category' => array(
             self::BELONGS_TO,
             'Category',
             'category_id',
             'on' => 'category_description.language_id=' . LanguageModel::getLanguageIdByCode(Yii::app()->language)
         ),
     );
 }
Exemplo n.º 11
0
    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'product_description' => array(self::HAS_ONE, 'ProductDescription', 'product_id',
                'condition' => 'product_description.language_id = ' . LanguageModel::getLanguageIdByCode(Yii::app()->language)),
            'variations' => array(self::MANY_MANY, 'Variation', 'product2variation(product_id, variation_id)'),
            'category' => array(
                self::MANY_MANY,
                'Category', 'category2product(product_id, category_id)',
            ),
            'category2product' => array(self::MANY_MANY, 'Category', 'category2product(product_id, category_id)'),

        );
    }
Exemplo n.º 12
0
 public function actionUpdate($new = false)
 {
     $this->topButtons = false;
     $model = $new === true ? new LanguageModel() : LanguageModel::model()->findByPk($_GET['id']);
     $this->breadcrumbs = array(Yii::t('app', 'LANGUAGES') => $this->createUrl('index'), $model->isNewRecord ? Yii::t('app', 'CREATED_LANG', 0) : CHtml::encode($model->name));
     $this->pageName = $model->isNewRecord ? Yii::t('app', 'CREATED_LANG', 0) : Yii::t('app', 'CREATED_LANG', 1);
     if (!$model) {
         throw new CHttpException(404, Yii::t('app', 'LANG_NOFIND'));
     }
     if (Yii::app()->request->isPostRequest) {
         $model->attributes = $_POST['LanguageModel'];
         if ($model->validate()) {
             $model->save();
             $this->redirect(array('index'));
         }
     }
     $this->render('update', array('model' => $model));
 }
Exemplo n.º 13
0
 static function returnArrayWithLang($model, $language_id = null)
 {
     if ($language_id == null) {
         $language_obj = LanguageModel::getDefault();
         $language_id = $language_obj->id;
     }
     $obj = Activerecord::createArrayFromModel($model);
     $lang_ref = $model::$lang_ref;
     $langObjects = $model->{$lang_ref};
     $langArray = array();
     foreach ($langObjects as $langObj) {
         $lang_id_field = $langObj::$lang_id_field;
         $lang_fields = $langObj::$fields;
         $lang = Activerecord::createArrayFromModel($langObj);
         $langArray[] = $lang;
         if ($langObj->{$lang_id_field} == $language_id) {
             foreach ($lang_fields as $f) {
                 $obj[$f] = $langObj->{$f};
             }
         }
     }
     $obj["lang"] = $langArray;
     return $obj;
 }
Exemplo n.º 14
0
 /**
  * @return array relational rules.
  */
 public function relations()
 {
     // NOTE: you may need to adjust the relation name and the related
     // class name for the relations automatically generated below.
     return array(
         'category_description' => array(
             self::HAS_ONE,
             'CategoryDescription',
             'category_id',
             'on' => 'category_description.language_id = ' . LanguageModel::getLanguageIdByCode(Yii::app()->language)
         ),
         'parent' => array(
             self::HAS_ONE,
             'CategoryDescription',
             '',
             'on' => 't.parent_id = parent.category_id
                 AND parent.language_id = ' . LanguageModel::getLanguageIdByCode(Yii::app()->language)
         ),
         'children' => array(self::HAS_MANY, 'Category', array('parent_id' => 'category_id'), 'order' => 'children.sort_order, children.category_id',
             'on' => 'children.status = 1 OR children.category_id IS NULL',
             'joinType' => 'LEFT JOIN'),
         'products' => array(self::MANY_MANY, 'Product', 'category2product(category_id, product_id)'),
     );
 }
Exemplo n.º 15
0
 /**
  * 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 the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = LanguageModel::model()->findByPk($id);
     if ($model === null)
         throw new CHttpException(404, 'The requested page does not exist.');
     return $model;
 }
Exemplo n.º 16
0
 public static function getAdminDefault()
 {
     $default_language = LanguageModel::find_by_admin_default("y");
     return $default_language;
 }
Exemplo n.º 17
0
 public function actionSearchProductByName()
 {
     if ($_GET['product_name']) {
         $c = new CDbCriteria();
         $c->with = array('product_description' => array('with' => array('product')), 'variations' => array('with' => array('variation_description')));
         //$c->together = true;
         $c->compare('product.status', 1);
         $c->compare('product_description.language_id', LanguageModel::getLanguageIdByCode(Yii::app()->language));
         $c->compare('variation_description.language_id', LanguageModel::getLanguageIdByCode(Yii::app()->language));
         $c->addCondition('product_name LIKE :product_name OR variation_name LIKE :variation_name OR variation_description LIKE :variation_description');
         $c->params[':product_name'] = '%' . $_GET['product_name'] . '%';
         $c->params[':variation_name'] = '%' . $_GET['product_name'] . '%';
         $c->params[':variation_description'] = '%' . $_GET['product_name'] . '%';
         $products = Product::model()->findAll($c);
         //CVarDumper::dump($products, 10, true);
         if (count($products) > 0) {
             $aResultProducts = array();
             foreach ($products as $product) {
                 $aResultProducts[$product->product_description->product_id] = $product->product_description->product_name;
                 if (!empty($product->variations)) {
                     foreach ($product->variations as $variation) {
                         if (strripos($variation->variation_description->variation_name, $_GET['product_name']) !== false) {
                             $aResultProducts[$product->product_description->product_id] .= ' (' . $variation->variation_description->variation_name . ')';
                             break;
                         }
                     }
                 }
             }
             echo json_encode(array('success' => 1, 'products' => $aResultProducts));
         } else {
             echo json_encode(array('success' => 0));
         }
     }
     die;
 }
Exemplo n.º 18
0
 /**
  * @param $code
  * @return array|mixed|null
  */
 public static function getLanguageIdByCode($code)
 {
     $model = LanguageModel::model()->findByAttributes(array('code' => $code));
     return ($model !== null) ? $model->id : '';
 }
Exemplo n.º 19
0
 /**
  * 
  * @return string
  */
 public static function autoDetectLanguage()
 {
     $sites = array();
     $languages = LanguageModel::model()->findAll();
     foreach ($languages as $lange) {
         //print_r($lange->code);
         $sites[$lange->code] = Yii::app()->request->hostInfo . "/" . $lange->code . '/';
     }
     $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
     if (!in_array($lang, array_keys($sites))) {
         $lang = Yii::app()->languageManager->default->code;
     }
     Yii::app()->language = $lang;
     // Yii::app()->controller->redirect($sites[$lang]);
     return $sites[$lang];
 }
Exemplo n.º 20
0
    public function actionUpdate($id)
    {
        $model = $this->loadModel($id);
        if (isset($_POST['deleteValID'])) {
            Value::model()->deleteAll('value_id=' . $_POST['deleteValID']);
            ValueDescription::model()->deleteAll('value_id=' . $_POST['deleteValID']);
            Attribute2value::model()->deleteAll('value_id=' . $_POST['deleteValID']);
            echo 'success';
            exit;
        }
        $lang_model = new LanguageModel;
        $AttrDescModel = new AttributeDescription;
        $Attribute2value = $this->loadAttrToValModel('attribute_id=' . $id);

        $ValueModel = new Value;
        $ValueDescription = new ValueDescription;

        $aLangNames = array();
        $aValNames = array();
        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        $allLangs = $lang_model->findAll('1', array('order' => 'id ASC'));
        $allLangsJS = array();
        $aValuesNames = array();
        foreach ($allLangs as $language) {
          $allLangsJS[$language['id']] = $language['code'];

          foreach ($Attribute2value as $record) {
            $aNames = $ValueDescription->find('language_id=' . $language['id'] . ' AND value_id=' . $record['value_id']);
            $aValuesNames[$record['value_id']][$language['code']]['value_id'] = $record['value_id'];
            $aValuesNames[$record['value_id']][$language['code']]['value_name'] = $aNames['value_name'];
            $aValuesNames[$record['value_id']][$language['code']]['language_id'] = $language['id'];
          }
        }

        $aAttrNames = $AttrDescModel->findAll("attribute_id = '" . $id . "'");
        foreach ($aAttrNames as $lng_attribute) {
            $aLangNames[$lng_attribute['language_id']] = $lng_attribute['attribute_name'];
        }

        if (isset($_POST['Attribute'])) {
            $model->attributes = $_POST['Attribute'];
            $model->updateByPk($id, $model->attributes);
            if (isset($_POST['AttributeDescription']['attribute_name'])) {
                foreach ($_POST['AttributeDescription']['attribute_name'] as $langId => $attrName) {
                    $attr_desc_model = new AttributeDescription;
                    $attr_desc_model->updateByPk(array('attribute_id' => $id, 'language_id' => $langId), array('attribute_name' => $attrName));
                }
            }

            if (isset($_POST['NewAttrValue'])) {
                foreach ($_POST['NewAttrValue'] as $spec_id => $new_val) {
                    $ValueModel = new Value;
                    $ValueModel->attributes = array(
                        'status' => 1,
                    );
                    $ValueModel->save();
                    $v_id = $ValueModel->getPrimaryKey();

                    foreach ($new_val as $lang_id => $value) {
                        if ($value != '') {
                            $ValueDescription = new ValueDescription;
                            $ValueDescription->attributes = array(
                                'value_id' => $v_id,
                                'language_id' => $lang_id,
                                'value_name' => $value,
                            );
                            $ValueDescription->save();
                        }
                    }

                    $Attribute2value = new Attribute2value;
                    $Attribute2value->attributes = array('attribute_id' => $id, 'value_id' => $v_id);
                    $Attribute2value->save();
                }
            }
            if (isset($_POST['ValueDescription']['value_name'])) {
                foreach ($_POST['ValueDescription']['value_name'] as $language_id => $lang_values) {
                    foreach ($lang_values as $value_id => $value_name) {
                        $value_desc_model = new ValueDescription;
                        $value_desc_model->updateByPk(array('value_id' => $value_id, 'language_id' => $language_id), array('value_name' => $value_name));
                    }
                }

            }
            $this->redirect(array('index'));
        }

        $this->render('update', array(
            'model' => $model,
            'allLangs' => $allLangs,
            'AttrDescModel' => $AttrDescModel,
            'aLangNames' => $aLangNames,
            'allLangsJS' => json_encode($allLangsJS),
            'aValuesNames' => $aValuesNames,
            'ValueDescription' => $ValueDescription,
        ));
    }
Exemplo n.º 21
0
    function actionAddVariation() {
        if (isset($_GET['product_id']) && $_GET['product_id']) {
            $variation = new Variation();
            $variation->save();

            $variation_id = $variation->getPrimaryKey();

            $product2variation = new Product2variation();
            $product2variation->product_id = $_GET['product_id'];
            $product2variation->variation_id = $variation_id;
            $product2variation->save();

            $allLangs = LanguageModel::model()->findAll('1', array('order'=> 'id ASC'));
            foreach ($allLangs as $language) {
                $variation_description = new VariationDescription();
                $variation_description->variation_id = $variation_id;
                $variation_description->language_id = $language['id'];
                $variation_description->save();
            }
            $this->actionUpdate($_GET['product_id']);
            die();
        }
    }