Пример #1
0
 public function detailAction()
 {
     $request = $this->getRequest();
     $table = new AttributeDescriptor();
     if ($request->isPost() && $this->form->isValid($request->getParams())) {
     } else {
         $attribArray = $table->find($request->getParam(AttributeDescriptor::COL_ID))->current()->toArray();
         $userTable = new User();
         $userArray = $userTable->find($attribArray[User::COL_ID])->current()->toArray();
         $attribArray += array('username' => $userArray[User::COL_USERNAME]);
         $this->form->isValid($attribArray);
         $this->view->form = $this->form;
         $this->render('form');
     }
     //ENDE: class ...
 }
Пример #2
0
 public function __construct($spec = '', $options = '', $group = '')
 {
     parent::__construct($spec, $options);
     $table = new AttributeDescriptor();
     $select = $table->select();
     $select->order(AttributeDescriptor::COL_NAME);
     if ($group != '') {
         $select->where(AttributeDescriptor::COL_GROUP . "= ?", $group);
     }
     $rowset = $table->fetchAll($select);
     $array = $rowset->toArray();
     $optArray = array(null => 'Please select');
     foreach ($array as $value) {
         $optArray = $optArray + array($value[AttributeDescriptor::COL_ID] => $value[AttributeDescriptor::COL_NAME]);
     }
     $this->setMultiOptions($optArray);
 }
Пример #3
0
 public function updateAction()
 {
     $request = $this->getRequest();
     $table = new AttributeDescriptor();
     if ($request->isPost() && $this->form->isValid($request->getParams())) {
         //		&& $this->sequenceUnique($this->form->getValue(AttributeDescriptor::COL_GROUP),$this->form->getValue(AttributeDescriptor::COL_SEQUENCE), intval($this->form->getValue(AttributeDescriptor::COL_ID)))) {
         $data = array(AttributeDescriptor::COL_NAME => $this->form->getValue(AttributeDescriptor::COL_NAME), AttributeDescriptor::COL_UNIT => $this->form->getValue(AttributeDescriptor::COL_UNIT), AttributeDescriptor::COL_DESCRIPTION => $this->form->getValue(AttributeDescriptor::COL_DESCRIPTION), AttributeDescriptor::COL_DEFAULT => $this->form->getValue(AttributeDescriptor::COL_DEFAULT), AttributeDescriptor::COL_REQUIRED => $this->form->getValue(AttributeDescriptor::COL_REQUIRED), AttributeDescriptor::COL_IS_STANDARD => $this->form->getValue(AttributeDescriptor::COL_IS_STANDARD), AttributeDescriptor::COL_ACTIVE => $this->form->getValue(AttributeDescriptor::COL_ACTIVE), AttributeDescriptor::COL_DATA_TYPE => $this->form->getValue(AttributeDescriptor::COL_DATA_TYPE), AttributeDescriptor::COL_FORM_TYPE => $this->form->getValue(AttributeDescriptor::COL_FORM_TYPE), AttributeDescriptor::COL_VALUE_LIST => $this->form->getValue(AttributeDescriptor::COL_VALUE_LIST), AttributeDescriptor::COL_SEQUENCE => $this->form->getValue(AttributeDescriptor::COL_SEQUENCE), AttributeDescriptor::COL_MULTIPLE => $this->form->getValue(AttributeDescriptor::COL_MULTIPLE), AttributeDescriptor::COL_SHOW_IN_LIST => $this->form->getValue(AttributeDescriptor::COL_SHOW_IN_LIST), AttributeDescriptor::COL_GROUP => $this->form->getValue(AttributeDescriptor::COL_GROUP));
         $table->update($data, AttributeDescriptor::COL_ID . '=' . intval($this->form->getValue(AttributeDescriptor::COL_ID)));
         $this->redirectTo();
     } else {
         $attribArray = $table->find($request->getParam(AttributeDescriptor::COL_ID))->current()->toArray();
         $userTable = new User();
         $userArray = $userTable->find($attribArray[User::COL_ID])->current()->toArray();
         $attribArray += array('username' => $userArray[User::COL_USERNAME]);
         $this->form->populate($attribArray);
         $this->view->form = $this->form;
         $this->render('form');
     }
 }
Пример #4
0
 public function addWhereToSelect($formValues)
 {
     //$this->select = $this->getSelectForGroups();
     $aliasArray = $this->aliasArray;
     //handle AND/OR search
     if ($formValues['kind'] == 'and') {
         foreach ($formValues as $key => $value) {
             if ($this->formKeyHasValue($key, $value)) {
                 //search for data sets with NULL values - e.g. old data sets before introduction of new attributes - isn't possible at the moment
                 //process possible meta data attributes
                 if (substr_compare($key, 'ATDE_', 0, 4, TRUE) == 0) {
                     //cut off ATDE_ to get only ID for querying in table
                     $keyAtDeId = substr($key, 5);
                     foreach ($aliasArray as $atDeId => $aliasTableAndColumn) {
                         if ($keyAtDeId == $atDeId) {
                             //Boolean Expressions: Int=0=>FALSE , Int=1=>TRUE
                             $atDeTable = new AttributeDescriptor();
                             $rowset = $atDeTable->find($atDeId);
                             if (count($rowset) == 1) {
                                 $rowsetArray = $rowset->toArray();
                                 $atDe = $rowsetArray[0];
                                 if ($atDe[AttributeDescriptor::COL_FORM_TYPE] == 'select') {
                                     //OLD
                                     //$partStatement = $tableAdapter->quoteInto($aliasTableAndColumn.' = ?', $value);
                                     //NEW
                                     //-------------------------------------------------------------
                                     //NOTE: standard zend element checkbox sets value for checked=1 AND unchecked=0,
                                     //      checkbox is always submitted
                                     //      standard zend element multicheckbox sets no value for unchecked
                                     //      multicheckbox without checked boxes is not submitted
                                     $partStatement = '';
                                     //handle last item differently
                                     //credit:grobemo
                                     //24-Apr-2009 08:13
                                     //http://de3.php.net/manual/en/control-structures.foreach.php
                                     $last_item = end($value);
                                     foreach ($value as $val) {
                                         if ($val == $last_item) {
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' = ?', $val);
                                         } else {
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' = ? OR ', $val);
                                         }
                                     }
                                     //-------------------------------------------------------------
                                 } elseif ($atDe[AttributeDescriptor::COL_FORM_TYPE] == 'text') {
                                     if ($atDe[AttributeDescriptor::COL_DATA_TYPE] == 'integer' || $atDe[AttributeDescriptor::COL_DATA_TYPE] == 'decimal' || $atDe[AttributeDescriptor::COL_DATA_TYPE] == 'date' || $atDe[AttributeDescriptor::COL_DATA_TYPE] == 'time' || $atDe[AttributeDescriptor::COL_DATA_TYPE] == 'datetime') {
                                         switch ($atDe[AttributeDescriptor::COL_DATA_TYPE]) {
                                             case 'integer':
                                                 $sqlDatatype = 'int';
                                                 break;
                                             case 'decimal':
                                                 $sqlDatatype = 'dec';
                                                 break;
                                                 //TODO handle other datatypes
                                         }
                                         if ($value['fromValue'] == NULL || $value['toValue'] == NULL) {
                                             //FROM or TO value empty
                                             $atDeName = $atDe[AttributeDescriptor::COL_NAME];
                                             echo "Info: FROM or TO value empty, {$atDeName} not used<br>";
                                             $keyProcessed = TRUE;
                                             break;
                                         } else {
                                             //$partStatement = $aliasTableAndColumn.' >= '.$value['fromValue'].' AND ';
                                             //$partStatement = $partStatement.$aliasTableAndColumn.' <= '.$value['toValue'];
                                             $partStatement = $this->dbAdapter->quoteInto($aliasTableAndColumn . ' >= ? AND ', $value['fromValue'], $sqlDatatype);
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' <= ?', $value['toValue'], $sqlDatatype);
                                             unset($sqlDatatype);
                                         }
                                     } elseif ($atDe[AttributeDescriptor::COL_DATA_TYPE] == 'string') {
                                         $partStatement = $this->dbAdapter->quoteInto($aliasTableAndColumn . ' LIKE ?', '%' . $value . '%');
                                     } else {
                                         throw new Zend_Exception("Error: processing search parameters");
                                     }
                                 } elseif ($atDe[AttributeDescriptor::COL_FORM_TYPE] == 'checkbox') {
                                     //NOTE: standard zend element checkbox sets value for checked=1 AND unchecked=0,
                                     //      checkbox is always submitted
                                     //      standard zend element multicheckbox sets no value for unchecked
                                     //      multicheckbox without checked boxes is not submitted
                                     //schema-definition specific
                                     if ($value == '1') {
                                         //checkbox is on
                                         $partStatement = $aliasTableAndColumn . ' = 1';
                                     } elseif ($value == '0' || $value == NULL) {
                                         //checkbox is off
                                         //do nothing to handle 0 and NULL (off and not defined yet)
                                         //$partStatement = $aliasTableAndColumn.' = 0';
                                     } else {
                                         throw new Zend_Exception("Error: processing search parameters");
                                     }
                                 } elseif ($atDe[AttributeDescriptor::COL_FORM_TYPE] == 'textarea') {
                                     $partStatement = $this->dbAdapter->quoteInto($aliasTableAndColumn . ' LIKE ?', '%' . $value . '%');
                                 } elseif ($atDe[AttributeDescriptor::COL_FORM_TYPE] == 'radio') {
                                     //OLD
                                     //$partStatement = $this->dbAdapter->quoteInto($aliasTableAndColumn.' = ?', $value);
                                     //NEW
                                     //-------------------------------------------------------------
                                     //NOTE: standard zend element checkbox sets value for checked=1 AND unchecked=0,
                                     //      checkbox is always submitted
                                     //      standard zend element multicheckbox sets no value for unchecked
                                     //      multicheckbox without checked boxes is not submitted
                                     $partStatement = '';
                                     //handle last item differently
                                     //credit:grobemo
                                     //24-Apr-2009 08:13
                                     //http://de3.php.net/manual/en/control-structures.foreach.php
                                     $last_item = end($value);
                                     foreach ($value as $val) {
                                         if ($val == $last_item) {
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' = ?', $val);
                                         } else {
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' = ? OR ', $val);
                                         }
                                     }
                                     //-------------------------------------------------------------
                                 } elseif ($atDe[AttributeDescriptor::COL_FORM_TYPE] == 'multiselect' || $atDe[AttributeDescriptor::COL_FORM_TYPE] == 'multicheckbox') {
                                     //NOTE: standard zend element checkbox sets value for checked=1 AND unchecked=0,
                                     //      checkbox is always submitted
                                     //      standard zend element multicheckbox sets no value for unchecked
                                     //      multicheckbox without checked boxes is not submitted
                                     $partStatement = '';
                                     /*handle last item differently
                                      * credit:grobemo
                                      * 24-Apr-2009 08:13
                                      * http://de3.php.net/manual/en/control-structures.foreach.php
                                      */
                                     $last_item = end($value);
                                     foreach ($value as $val) {
                                         if ($val == $last_item) {
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' = ?', $val);
                                         } else {
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' = ? OR ', $val);
                                         }
                                     }
                                 } else {
                                     throw new Zend_Exception("Error: processing search parameters");
                                 }
                                 //finally append the where to the select(whole metadata)
                                 if (isset($partStatement)) {
                                     $this->select->where($partStatement);
                                 }
                                 unset($partStatement);
                             } else {
                                 throw new Zend_Exception("Error: count(rowset) from attribute_desc where ATDE_ID = {$atdeId} is not 1");
                             }
                             //$partStatement = $this->dbAdapter->quoteInto($aliasTableAndColumn.' like ?', '%'.$value.'%');
                             //$this->select->where($partStatement);
                             //set to TRUE jumps to next key
                             $keyProcessed = TRUE;
                             break;
                         } else {
                             $keyProcessed = FALSE;
                         }
                     }
                 } else {
                     //no ATDE_ID attribute key
                     $keyProcessed = FALSE;
                 }
                 //process direct attributes
                 //only if key was not processed already
                 if (!$keyProcessed) {
                     //$tableRow = $this->dbAdapter->quoteIdentifier($key);
                     $partStatement = $this->dbAdapter->quoteInto($key . ' like ?', '%' . $value . '%');
                     $this->select->where($partStatement);
                 }
             }
             //end, process next key
         }
     }
     if ($formValues['kind'] == 'or') {
         //due to whole sql-statement
         //don't use select->orWhere() method, instead concatenate strings with OR
         //to reduce usage of brackets
         //and mixed usage of where / orWhere (first condition where, second and more conditions orWhere)
         $orWhere = '';
         foreach ($formValues as $key => $value) {
             if ($this->formKeyHasValue($key, $value)) {
                 //search for data sets with NULL values - e.g. old data sets before introduction of new attributes - isn't possible at the moment
                 //process possible meta data attributes
                 if (substr_compare($key, 'ATDE_', 0, 4, TRUE) == 0) {
                     $keyAtDeId = substr($key, 5);
                     foreach ($aliasArray as $atDeId => $aliasTableAndColumn) {
                         //cut off ATDE_ to get only ID for querying in table
                         if ($keyAtDeId == $atDeId) {
                             //Boolean Expressions: Int=0=>FALSE , Int=1=>TRUE
                             $atDeTable = new AttributeDescriptor();
                             $rowset = $atDeTable->find($atDeId);
                             if (count($rowset) == 1) {
                                 $rowsetArray = $rowset->toArray();
                                 $atDe = $rowsetArray[0];
                                 if ($atDe[AttributeDescriptor::COL_FORM_TYPE] == 'select') {
                                     //OLD
                                     //$partStatement = $this->dbAdapter->quoteInto($aliasTableAndColumn.' = ?', $value);
                                     //NEW
                                     //-------------------------------------------------------------
                                     //NOTE: standard zend element checkbox sets value for checked=1 AND unchecked=0,
                                     //      checkbox is always submitted
                                     //      standard zend element multicheckbox sets no value for unchecked
                                     //      multicheckbox without checked boxes is not submitted
                                     $partStatement = '';
                                     //handle last item differently
                                     //credit:grobemo
                                     //24-Apr-2009 08:13
                                     //http://de3.php.net/manual/en/control-structures.foreach.php
                                     $last_item = end($value);
                                     foreach ($value as $val) {
                                         if ($val == $last_item) {
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' = ?', $val);
                                         } else {
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' = ? OR ', $val);
                                         }
                                     }
                                     //-------------------------------------------------------------
                                 } elseif ($atDe[AttributeDescriptor::COL_FORM_TYPE] == 'text') {
                                     if ($atDe[AttributeDescriptor::COL_DATA_TYPE] == 'integer' || $atDe[AttributeDescriptor::COL_DATA_TYPE] == 'decimal' || $atDe[AttributeDescriptor::COL_DATA_TYPE] == 'date' || $atDe[AttributeDescriptor::COL_DATA_TYPE] == 'time' || $atDe[AttributeDescriptor::COL_DATA_TYPE] == 'datetime') {
                                         switch ($atDe[AttributeDescriptor::COL_DATA_TYPE]) {
                                             case 'integer':
                                                 $sqlDatatype = 'int';
                                                 break;
                                             case 'decimal':
                                                 $sqlDatatype = 'dec';
                                                 break;
                                                 //TODO handle other datatypes
                                         }
                                         if ($value['fromValue'] == NULL || $value['toValue'] == NULL) {
                                             //FROM or TO value empty
                                             $atDeName = $atDe[AttributeDescriptor::COL_NAME];
                                             echo "Info: FROM or TO value empty, {$atDeName} not used<br>";
                                             $keyProcessed = TRUE;
                                             break;
                                         } else {
                                             //$partStatement = $aliasTableAndColumn.' >= '.$value['fromValue'].' AND ';
                                             //$partStatement = $partStatement.$aliasTableAndColumn.' <= '.$value['toValue'];
                                             $partStatement = '(';
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' >= ? AND ', $value['fromValue'], $sqlDatatype);
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' <= ?)', $value['toValue'], $sqlDatatype);
                                         }
                                     } elseif ($atDe[AttributeDescriptor::COL_DATA_TYPE] == 'string') {
                                         $partStatement = $this->dbAdapter->quoteInto($aliasTableAndColumn . ' LIKE ?', '%' . $value . '%');
                                     } else {
                                         throw new Zend_Exception("Error: processing search parameters");
                                     }
                                 } elseif ($atDe[AttributeDescriptor::COL_FORM_TYPE] == 'checkbox') {
                                     //NOTE: standard zend element checkbox sets value for checked=1 AND unchecked=0,
                                     //      checkbox is always submitted
                                     //      standard zend element multicheckbox sets no value for unchecked
                                     //      multicheckbox without checked boxes is not submitted
                                     //schema-definition specific
                                     if ($value == '1') {
                                         //checkbox is on
                                         $partStatement = $aliasTableAndColumn . ' = 1';
                                     } elseif ($value == '0' || $value == NULL) {
                                         //checkbox is off
                                         //do nothing to handle 0 and NULL (off and not defined yet)
                                         //$partStatement = $aliasTableAndColumn.' = 0';
                                     } else {
                                         throw new Zend_Exception("Error: processing search parameters");
                                     }
                                 } elseif ($atDe[AttributeDescriptor::COL_FORM_TYPE] == 'textarea') {
                                     $partStatement = $this->dbAdapter->quoteInto($aliasTableAndColumn . ' LIKE ?', '%' . $value . '%');
                                 } elseif ($atDe[AttributeDescriptor::COL_FORM_TYPE] == 'radio') {
                                     //OLD
                                     //$partStatement = $this->dbAdapter->quoteInto($aliasTableAndColumn.' = ?', $value);
                                     //NEW
                                     //-------------------------------------------------------------
                                     //NOTE: standard zend element checkbox sets value for checked=1 AND unchecked=0,
                                     //      checkbox is always submitted
                                     //      standard zend element multicheckbox sets no value for unchecked
                                     //      multicheckbox without checked boxes is not submitted
                                     $partStatement = '';
                                     //handle last item differently
                                     //credit:grobemo
                                     //24-Apr-2009 08:13
                                     //http://de3.php.net/manual/en/control-structures.foreach.php
                                     $last_item = end($value);
                                     foreach ($value as $val) {
                                         if ($val == $last_item) {
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' = ?', $val);
                                         } else {
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' = ? OR ', $val);
                                         }
                                     }
                                     //-------------------------------------------------------------
                                 } elseif ($atDe[AttributeDescriptor::COL_FORM_TYPE] == 'multiselect' || $atDe[AttributeDescriptor::COL_FORM_TYPE] == 'multicheckbox') {
                                     //NOTE: standard zend element checkbox sets value for checked=1 AND unchecked=0,
                                     //      checkbox is always submitted
                                     //      standard zend element multicheckbox sets no value for unchecked
                                     //      multicheckbox without checked boxes is not submitted
                                     $partStatement = '(';
                                     /*handle last item differently
                                      * credit:grobemo
                                      * 24-Apr-2009 08:13
                                      * http://de3.php.net/manual/en/control-structures.foreach.php
                                      */
                                     $last_item = end($value);
                                     foreach ($value as $val) {
                                         if ($val == $last_item) {
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' = ?)', $val);
                                         } else {
                                             $partStatement = $partStatement . $this->dbAdapter->quoteInto($aliasTableAndColumn . ' = ? OR ', $val);
                                         }
                                     }
                                 } else {
                                     throw new Zend_Exception("Error: processing search parameters");
                                 }
                                 //append the where to the "where or where" container
                                 if (isset($partStatement)) {
                                     if ($orWhere == '') {
                                         $orWhere = $partStatement;
                                     } else {
                                         $orWhere = $orWhere . ' OR ' . $partStatement;
                                     }
                                 }
                                 unset($partStatement);
                             } else {
                                 throw new Zend_Exception("Error: count(rowset) from attribute_desc where ATDE_ID = {$atdeId} is not 1");
                             }
                             //$partStatement = $this->dbAdapter->quoteInto($aliasTableAndColumn.' like ?', '%'.$value.'%');
                             //$this->select->where($partStatement);
                             //set to TRUE jumps to next key
                             $keyProcessed = TRUE;
                             break;
                         } else {
                             $keyProcessed = FALSE;
                         }
                     }
                 } else {
                     //no ATDE_ID attribute key
                     $keyProcessed = FALSE;
                 }
                 //process direct attributes
                 //only if key was not processed already
                 if (!$keyProcessed) {
                     //$tableRow = $this->dbAdapter->quoteIdentifier($key);
                     $partStatement = $this->dbAdapter->quoteInto($key . ' like ?', '%' . $value . '%');
                     //append the where to the "where or where" container
                     if (isset($partStatement)) {
                         if ($orWhere == '') {
                             $orWhere = $partStatement;
                         } else {
                             $orWhere = $orWhere . ' OR ' . $partStatement;
                         }
                     }
                     unset($partStatement);
                 }
             }
             //end, process next key
         }
         //finally append the where to the select(whole metadata)
         if ($orWhere != '') {
             $this->select->where($orWhere);
         }
     }
     return $this->select;
 }
Пример #5
0
 //due to whole sql-statement
 //don't use select->orWhere() method, instead add strings with OR
 //to reduce usage of brackets
 //and mixed usage of where / orWhere (first condition where, second and more conditions orWhere)
 $orWhere = '';
 foreach ($formValues as $key => $value) {
     if ($this->formKeyHasValue($key, $value)) {
         //search for data sets with NULL values - e.g. old data sets before introduction of new attributes - isn't possible at the moment
         //process possible meta data attributes
         if (substr_compare($key, 'ATDE_', 0, 4, TRUE) == 0) {
             $keyAtDeId = substr($key, 5);
             foreach ($aliasArray as $atDeId => $aliasTableAndColumn) {
                 //cut off ATDE_ to get only ID for querying in table
                 if ($keyAtDeId == $atDeId) {
                     //Boolean Expressions: Int=0=>FALSE , Int=1=>TRUE
                     $atDeTable = new AttributeDescriptor();
                     $rowset = $atDeTable->find($atDeId);
                     if (count($rowset) == 1) {
                         $rowsetArray = $rowset->toArray();
                         $atDe = $rowsetArray[0];
                         if ($atDe[AttributeDescriptor::COL_FORM_TYPE] == 'select') {
                             //OLD
                             //$partStatement = $tableAdapter->quoteInto($aliasTableAndColumn.' = ?', $value);
                             //$partStatement = $aliasTableAndColumn.' = '.$value;
                             //NEW
                             //-------------------------------------------------------------
                             //NOTE: standard zend element checkbox sets value for checked=1 AND unchecked=0,
                             //      checkbox is always submitted
                             //      standard zend element multicheckbox sets no value for unchecked
                             //      multicheckbox without checked boxes is not submitted
                             $partStatement = '';