Ejemplo n.º 1
0
 protected function renderFieldCategory(ConfigFieldCategory $fieldCategory)
 {
     $str = "";
     $fields = $fieldCategory->getConfigFields();
     foreach ($fields as $field) {
         $str .= "<fieldset>";
         $str .= "<legend>" . $field->getName() . "</legend>";
         $fieldId = $field->getId();
         $cField = new Criteria();
         $cField->add(FieldValuePeer::FIELD_ID, $fieldId);
         /*$c1 = $cField->getNewCriterion(FieldValuePeer::VALUE, $query.'%', Criteria::LIKE);
           $c2 = $cField->getNewCriterion(FieldValuePeer::VALUE, "", Criteria::NOT_EQUAL);
           $c1->addAnd($c2);        
           $cField->addAnd($c1);*/
         $cField->add(FieldValuePeer::VALUE, "", Criteria::NOT_EQUAL);
         $cField->addGroupByColumn(FieldValuePeer::VALUE);
         $cField->addAscendingOrderByColumn(FieldValuePeer::VALUE);
         $cField->setLimit(15);
         $values = FieldValuePeer::doSelect($cField);
         $valueIndex = 0;
         foreach ($values as $value) {
             $str .= "<label>" . $value->getValue() . "</label>";
             $str .= "<input type=\"checkbox\" name=\"fields[" . $field->getId() . "][{$valueIndex}]\"  id=\"fields_" . $field->getId() . "_{$valueIndex}\" value=\"" . $value->getValue() . "\" /><br>";
             $valueIndex++;
         }
         $str .= "</fieldset>";
     }
     return $str;
 }
Ejemplo n.º 2
0
 public static function getFieldValue($fieldId, $configId)
 {
     $c = new Criteria();
     $c->add(FieldValuePeer::FIELD_ID, $fieldId);
     $c->add(FieldValuePeer::CONFIG_ID, $configId);
     if ($value = FieldValuePeer::doSelectOne($c)) {
         return $value;
     } else {
         $value = new FieldValue();
         $value->setFieldId($fieldId);
         $value->setConfigId($configId);
         return $value;
     }
 }
Ejemplo n.º 3
0
 public function execute($request)
 {
     $fieldName = $this->getRequestParameter('field');
     $query = $this->getRequestParameter('query');
     //get field ID
     $fieldNameArr = explode('_', $fieldName);
     $fieldId = $fieldNameArr[1];
     $cField = new Criteria();
     $cField->add(FieldValuePeer::FIELD_ID, $fieldId);
     $c1 = $cField->getNewCriterion(FieldValuePeer::VALUE, $query . '%', Criteria::LIKE);
     $c2 = $cField->getNewCriterion(FieldValuePeer::VALUE, "", Criteria::NOT_EQUAL);
     $c1->addAnd($c2);
     $cField->addAnd($c1);
     $cField->addGroupByColumn(FieldValuePeer::VALUE);
     $cField->addAscendingOrderByColumn(FieldValuePeer::VALUE);
     $cField->setLimit(15);
     $this->values = FieldValuePeer::doSelect($cField);
     $this->getResponse()->setContentType('application/json');
 }
Ejemplo n.º 4
0
 public function makeConfigName()
 {
     $configName = "C: ";
     $fieldCats = array(1, 2);
     foreach ($fieldCats as $cid) {
         $fieldCat = ConfigFieldCategoryPeer::retrieveByPK($cid);
         $fields = $fieldCat->getFields();
         foreach ($fields as $f) {
             $cFieldValues = new Criteria();
             $cFieldValues->add(FieldValuePeer::CONFIG_ID, $this->getId());
             $cFieldValues->add(FieldValuePeer::FIELD_ID, $f->getId());
             $fieldValues = FieldValuePeer::doSelect($cFieldValues);
             foreach ($fieldValues as $fieldValue) {
                 $configName .= $fieldValue->getValue() . " ";
             }
         }
         $configName .= '-';
     }
     return $configName;
 }
Ejemplo n.º 5
0
 /**
  * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
  * feature (like MySQL or SQLite).
  *
  * This method is not very speedy because it must perform a query first to get
  * the implicated records and then perform the deletes by calling those Peer classes.
  *
  * This method should be used within a transaction if possible.
  *
  * @param      Criteria $criteria
  * @param      PropelPDO $con
  * @return     int The number of affected rows (if supported by underlying database driver).
  */
 protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
 {
     // initialize var to track total num of affected rows
     $affectedRows = 0;
     // first find the objects that are implicated by the $criteria
     $objects = ConfigFieldPeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         // delete related FieldValue objects
         $criteria = new Criteria(FieldValuePeer::DATABASE_NAME);
         $criteria->add(FieldValuePeer::FIELD_ID, $obj->getId());
         $affectedRows += FieldValuePeer::doDelete($criteria, $con);
     }
     return $affectedRows;
 }
Ejemplo n.º 6
0
 public function execute($request)
 {
     //get params
     $this->brand = $this->getRequestParameter('brand');
     $this->series = $this->getRequestParameter('series');
     $this->model = $this->getRequestParameter('model');
     $this->configId = $this->getRequestParameter('config_id');
     //get image files
     $this->mainImage = $this->getRequest()->getFiles('main_image');
     $this->otherImages = $this->getRequest()->getFiles('other_images');
     //print_r($this->otherImages);
     //exit ();
     //load/create series and model
     if (SeriesPeer::isNew($this->series)) {
         //create new series
         $seriesObj = new Series();
         $seriesObj->setSeriesName($this->series);
         $seriesObj->setBrandId($this->brand);
         $seriesObj->save();
         //create new model
         $modelObj = new Model();
         $modelObj->setModelName($this->model);
         $modelObj->setSeries($seriesObj);
         $modelObj->save();
     } else {
         //load series object
         $seriesObj = SeriesPeer::getSeriesByName($this->series);
         if (ModelPeer::isNew($this->model)) {
             //create new model
             $modelObj = new Model();
             $modelObj->setModelName($this->model);
             $modelObj->setSeries($seriesObj);
             $modelObj->save();
         } else {
             $modelObj = ModelPeer::getModelByName($this->model);
         }
     }
     //////////////////////
     if (($this->isNew = $this->getRequestParameter('is_new')) == 'true') {
         //create new config
         $config = new Config();
         $config->setConfigName($this->getRequestParameter('name'));
         $config->setModel($modelObj);
         $config->save();
         //load config fields
         $configFields = ConfigFieldPeer::doSelect(new Criteria());
         foreach ($configFields as $configField) {
             //get param
             if ($this->hasRequestParameter("field_" . $configField->getId())) {
                 //if (strlen($this->getRequestParameter("field_".$configField->getId())) > 0 )
                 //{
                 $fieldValue = new FieldValue();
                 $fieldValue->setConfig($config);
                 $fieldValue->setFieldId($configField->getId());
                 $fieldValue->setValue($this->getRequestParameter("field_" . $configField->getId()));
                 $fieldValue->save();
                 //}
             }
         }
     } else {
         //load config
         $config = ConfigPeer::retrieveByPK($this->configId);
         //$config->setConfigName($this->getRequestParameter('name'));
         $config->setModel($modelObj);
         $config->save();
         //load config fields
         $configFields = ConfigFieldPeer::doSelect(new Criteria());
         foreach ($configFields as $configField) {
             //get param
             if ($this->hasRequestParameter("field_" . $configField->getId())) {
                 //if (strlen($this->getRequestParameter("field_".$configField->getId())) > 0 )
                 //{
                 $fieldValue = FieldValuePeer::getFieldValue($configField->getId(), $config->getId());
                 $fieldValue->setValue($this->getRequestParameter("field_" . $configField->getId()));
                 $fieldValue->save();
                 //}
             }
         }
     }
     //save main image
     MediaPeer::saveMedia($this->mainImage, $modelObj->getId(), MediaPeer::IMAGE, 'Model', true);
     //save other images
     foreach ($this->otherImages as $image) {
         MediaPeer::saveMedia($image, $modelObj->getId(), MediaPeer::IMAGE, 'Model', false);
     }
     if (($saveAndNew = $this->getRequestParameter('save_and_new')) == 'true') {
         $this->redirect('config/newconfig');
     } else {
         $this->redirect('config/editconfig?id=' . $config->getId());
     }
 }
Ejemplo n.º 7
0
            ?>
" class="dynamic-fields" value=""></input> <span><?php 
            echo $field->getHtmlComment();
            ?>
</span>
                <?php 
        } else {
            ?>
                    <input type="text" name="<?php 
            echo 'field_' . $field->getId();
            ?>
" id="<?php 
            echo 'field_' . $field->getId();
            ?>
" class="dynamic-fields" value="<?php 
            echo FieldValuePeer::getFieldValue($field->getId(), $config->getId())->getValue();
            ?>
"></input> <span><?php 
            echo $field->getHtmlComment();
            ?>
</span>
                <?php 
        }
        ?>
                
            </div>
            <?php 
    }
    ?>
            
        </fieldset>
Ejemplo n.º 8
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this ConfigField is new, it will return
  * an empty collection; or if this ConfigField has previously
  * been saved, it will retrieve related FieldValues from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in ConfigField.
  */
 public function getFieldValuesJoinConfig($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     if ($criteria === null) {
         $criteria = new Criteria(ConfigFieldPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collFieldValues === null) {
         if ($this->isNew()) {
             $this->collFieldValues = array();
         } else {
             $criteria->add(FieldValuePeer::FIELD_ID, $this->id);
             $this->collFieldValues = FieldValuePeer::doSelectJoinConfig($criteria, $con, $join_behavior);
         }
     } else {
         // the following code is to determine if a new query is
         // called for.  If the criteria is the same as the last
         // one, just return the collection.
         $criteria->add(FieldValuePeer::FIELD_ID, $this->id);
         if (!isset($this->lastFieldValueCriteria) || !$this->lastFieldValueCriteria->equals($criteria)) {
             $this->collFieldValues = FieldValuePeer::doSelectJoinConfig($criteria, $con, $join_behavior);
         }
     }
     $this->lastFieldValueCriteria = $criteria;
     return $this->collFieldValues;
 }
Ejemplo n.º 9
0
 public function executeProcessConfigForm(sfWebRequest $request)
 {
     $data = $request->getGetParameters();
     $config = new Config();
     if ($data['cid'] == '-1') {
         // New Config
         $config->setModelId($data['mid']);
         $config->save();
         foreach ($data as $field => $value) {
             if ($field != 'cid' && $field != 'mid') {
                 $fv = new FieldValue();
                 $fv->setConfigId($config->getId());
                 $fv->setFieldId(intval($field));
                 $fv->setValue($value);
                 //echo intval($field)."\n";
                 $fv->save();
             }
         }
     } else {
         $config = ConfigPeer::retrieveByPK($data['cid']);
         foreach ($data as $field => $value) {
             if ($field != 'cid' && $field != 'mid') {
                 $c = new Criteria();
                 $c->add(FieldValuePeer::FIELD_ID, intval($field));
                 $c->add(FieldValuePeer::CONFIG_ID, $config->getId());
                 $fv = FieldValuePeer::doSelectOne($c);
                 if (!is_object($fv)) {
                     $fv = new FieldValue();
                     $fv->setConfigId($config->getId());
                     $fv->setFieldId(intval($field));
                 }
                 $fv->setValue($value);
                 //echo intval($fv->getValue())."#";
                 //print_r($fv, FALSE);
                 $fv->save();
             }
         }
     }
     $this->res = $config->getId();
 }
Ejemplo n.º 10
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(FieldValuePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(FieldValuePeer::DATABASE_NAME);
         $criteria->add(FieldValuePeer::ID, $pks, Criteria::IN);
         $objs = FieldValuePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Ejemplo n.º 11
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = FieldValuePeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setFieldId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setConfigId($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setValue($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setRating($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setCreatedAt($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setUpdatedAt($arr[$keys[6]]);
     }
 }