Exemple #1
0
 public function run()
 {
     $module = $this->controller->get('m', $this->controller->taxModule);
     if ($module == '') {
         $module = $this->controller->taxModule;
     }
     $voc = $this->controller->getVocabulary();
     if (is_object($voc)) {
         $v = $voc->id;
         $vob = $voc;
     } else {
         $v = $this->controller->get('v', 0);
         $vob = Vocabulary::model()->findByPk($v);
         if (!is_object($vob)) {
             throw new CHttpException(400, Yii::t('Xpress', 'Invalid Type ID.'));
         }
     }
     $this->controller->voc = $v;
     $propertyClassName = $vob->propertyClassName;
     $propertyModule = $vob->propertyModule;
     $property = '';
     if (Yii::app()->request->IsPostRequest) {
         // save posted data
         $model = $this->saveData($module, $v, $propertyModule, $propertyClassName);
     } else {
         // show edit form
         $id = $this->controller->get('id', 0);
         $model = $this->getTerm($id, $v);
         $property = $this->getProperty($id, $propertyClassName);
     }
     $this->controller->render('update', array('model' => $model, 'v' => $v, 'module' => $module, 'property' => $property, 'propertyModule' => $propertyModule, 'propertyClassName' => $propertyClassName));
 }
Exemple #2
0
 /**
  * get all vocabularies by module
  * valid current vocabulary
  * 
  * @param int $type vocabulary
  * @param string $module module ID
  * 
  * @return array
  */
 protected function getVocabularies($type, $module)
 {
     $criteria = new CDbCriteria();
     $criteria->compare('module', $module);
     $criteria->order = 'name';
     $types = Vocabulary::model()->findAll($criteria);
     if (count($types)) {
         $types = CHtml::listData($types, 'id', 'name');
     }
     if ($type && !array_key_exists($type, $types)) {
         $types = array();
         //throw new CHttpException(500, 'Invalid Type');
     }
     return $types;
 }
Exemple #3
0
 /**
  * find all vocavularies of current object
  * 
  * @param int $state vocabulary state
  * @return array Vocabulary
  */
 public function getVocabularies($state = Vocabulary::STATE_ACTIVE)
 {
     $criteria = new CDbCriteria();
     $criteria->join = "INNER JOIN " . SITE_ID . '_' . "taxonomy_term tt ON tt.v_id = t.id" . "\n INNER JOIN " . SITE_ID . '_' . "taxonomy_index ti ON ti.term_id = tt.id";
     if (is_numeric($this->taxonomy)) {
         $criteria->compare('t.id', $this->taxonomy);
     } else {
         $criteria->compare('t.alias', $this->taxonomy);
     }
     $criteria->compare('t.module', $this->module);
     $criteria->compare('t.state', $state);
     $objectId = (int) $this->getOwner()->{$this->objectAttribute};
     $criteria->compare('ti.object_id', $objectId);
     return Vocabulary::model()->findAll($criteria);
 }
Exemple #4
0
 /**
  * find terms recursive
  * 
  * @param Term $parent
  */
 protected function findTermsRecursive($parent, $level = 0, $path = '/', $state = Term::STATE_ACTIVE, $orderBy = 'ordering')
 {
     $data = $parent->attributes;
     $data['level'] = $level++;
     $vob = Vocabulary::model()->findByPk($parent->v_id);
     if (is_object($vob)) {
         $propertyClassName = $vob->propertyClassName;
         if (!empty($propertyClassName)) {
             $model = new $propertyClassName();
             $property = $model->findByAttributes(array('term_id' => $parent->id, 'status' => $state));
             if (is_object($property)) {
                 $properties = $property->attributes;
                 unset($properties['id'], $properties['status'], $properties['creation_datetime'], $properties['last_update'], $properties['created_by'], $properties['updated_by'], $properties['term_id']);
                 $data['properties'] = $properties;
             }
         }
     }
     $children = $parent->children(array('order' => $orderBy, 'condition' => 'children.state=:state', 'params' => array(':state' => $state)));
     if (is_array($children) && count($children)) {
         $data['children'] = array();
         foreach ($children as $term) {
             Yii::trace('findTermsRecursive in ' . $orderBy, 'system.db.abc');
             $data['children'][] = $this->findTermsRecursive($term, $level, '/', $state, $orderBy);
         }
     }
     return $data;
 }
 /**
  * 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 = Vocabulary::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemple #6
0
echo $form->labelEx($model, 'name');
?>
		<?php 
echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 255));
?>
		<?php 
echo $form->error($model, 'name');
?>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'vid');
?>
		<?php 
echo $form->listBox($model, 'vid', CHtml::listData(Vocabulary::model()->findAll(), 'id', 'name'), array('size' => 1));
?>
		<?php 
echo $form->error($model, 'vid');
?>
	</div>
    <div class="row">
        <?php 
echo $form->labelEx($model, 'parent');
?>
        <?php 
echo $form->listBox($model, 'parent', $listData, array('size' => 1));
?>
        <?php 
echo $form->error($model, 'parent');
?>
Exemple #7
0
<?php

$vocName = 'Category';
$voc = $this->vocabulary;
if (is_object($voc)) {
    $vocName = $voc->name;
}
$first_voc_id = '';
$first_voc = Vocabulary::model()->find(array('order' => 'name ASC', 'condition' => 'module=:module', 'params' => array(':module' => $module)));
if (!is_null($first_voc)) {
    $first_voc_id = $first_voc->id;
}
$this->breadcrumbs = array();
$this->breadcrumbs[$module] = array('/Admin/term/index', 'module' => $module, 'type' => $first_voc_id);
$this->breadcrumbs[$vocName] = array('/Admin/term/index', 'module' => $module, 'type' => !is_null($voc) ? $voc->id : '');
$this->breadcrumbs[] = $model->id ? 'Update' : 'Create';
$this->menu = array();
?>

<?php 
if ($model->id) {
    ?>
<h1>Edit <?php 
    echo CHtml::encode($model->name);
    ?>
</h1>
<?php 
} else {
    ?>
<h1>Create Term</h1>
<?php 
Exemple #8
0
<?php

$this->breadcrumbs = array('Danh mục');
$this->menu = array(array('label' => 'Danh sách', 'url' => array('admin')), array('label' => 'Tạo mới', 'url' => array('create')));
?>

<h1>Danh mục</h1>

<?php 
$this->widget('zii.widgets.grid.CGridView', array('id' => 'term-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('id', 'name', array('name' => 'vid', 'value' => 'GxHtml::valueEx($data->v)', 'filter' => GxHtml::listDataEx(Vocabulary::model()->findAllAttributes(null, true))), array('class' => 'CButtonColumn', 'template' => '{update}{delete}'))));