Ejemplo n.º 1
0
 public function setTagsArray(array $data)
 {
     // reset dei tag per semplificare lo script
     ProductTag::model()->deleteAll('product=:p', array(':p' => $this->id));
     // data attuale
     $now = new DateTime();
     $timestamp = $now->format('Y-m-d H-i-s');
     // ricerca dei tag e creazione dei link
     foreach ($data as $tagName) {
         $tag = Tag::model()->find('name=:nm', array(':nm' => $tagName));
         /** @var Tag $tag */
         if ($tag == null) {
             $tag = new Tag();
             $tag->name = $tagName;
             $tag->description = ucwords($tagName);
             $tag->timestamp = $timestamp;
             $tag->insert();
         }
         $productTag = ProductTag::model()->find('product=:p AND tag=:t', array(':p' => $this->id, ':t' => $tag->id));
         /** @var ProductTag $productTag */
         if ($productTag == null) {
             $productTag = new ProductTag();
             $productTag->product = $this->id;
             $productTag->tag = $tag->id;
             $productTag->insert();
         }
     }
 }
Ejemplo n.º 2
0
?>
		<?php 
echo $form->listBox($product, 'categories', CHtml::listData(Yii::app()->db->createCommand("SELECT CONCAT(REPEAT('-----', level-2), name) AS name, id FROM product_category ORDER BY lft LIMIT 18446744073709551615 OFFSET 1")->query(), 'id', 'name'), array("multiple" => "multiple", 'style' => 'height: 300px;'));
?>
		<?php 
echo $form->error($product, 'categories');
?>
	</div>
	<p class="note">Utilisez la touche "CTRL" pour sélection multiple.</p>
	
	<div class="row">
		<?php 
echo $form->labelEx($product, 'tags');
?>
		<?php 
echo $form->listBox($product, 'tags', CHtml::listData(ProductTag::model()->findAll(), 'id', 'name'), array("multiple" => "multiple", 'style' => 'height: 150px;'));
?>
		<?php 
echo $form->error($product, 'tags');
?>
	</div>
	<p class="note">Utilisez la touche "CTRL" pour sélection multiple.</p>

	<div class="row">
		<?php 
echo $form->labelEx($product, 'price_regular');
?>
		<?php 
echo $form->textField($product, 'price_regular', array('style' => 'width: 60%;'));
?>
		<?php 
Ejemplo n.º 3
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  *
  * @param integer $id
  *          the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         $model = $this->loadModel($id);
         if ($model->imageExists) {
             unlink($model->imagePath);
         }
         ProductTag::model()->deleteAll('product=:p', array(':p' => $model->id));
         $model->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
         }
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }