/**
  * This function is copied from the database manager because Phprojekt_Item_Abstract mistakenly expects
  * it to be a database manager.
  */
 public function getInfo($order, $column)
 {
     $column = Phprojekt_ActiveRecord_Abstract::convertVarFromSql($column);
     $fields = $this->_getFields();
     $result = array();
     foreach ($fields as $field) {
         if (isset($field->{$column})) {
             $result[] = $field->{$column};
         }
     }
     return $result;
 }
Example #2
0
 /**
  * Delete all the files uploaded in the upload fields.
  *
  * @return void
  */
 public function deleteUploadFiles()
 {
     // If there is any upload file -> delete the files from the server
     $fields = $this->getInformation()->getInfo(Phprojekt_ModelInformation_Default::ORDERING_FORM, Phprojekt_DatabaseManager::COLUMN_NAME);
     foreach ($fields as $field) {
         $field = Phprojekt_ActiveRecord_Abstract::convertVarFromSql($field);
         if ($this->getInformation()->getType($field) == 'upload') {
             $filesField = $this->{$field};
             $files = Default_Helpers_Upload::parseModelValues($filesField);
             Default_Helpers_Upload::deleteFiles($files);
         }
     }
 }
Example #3
0
 /**
  * Get all the string values from the Object.
  *
  * Allow only text field (varchar, text, tinytext and longtext).
  *
  * @param Phprojekt_Item_Abstract $object The item object.
  *
  * @return array Array with allowed values.
  */
 private function _getObjectDataToIndex($object)
 {
     $allow = array();
     $allow[] = 'varchar';
     $allow[] = 'text';
     $allow[] = 'tinytext';
     $allow[] = 'longtext';
     $data = array();
     $metaData = $object->_metadata;
     foreach ($metaData as $field => $fieldInfo) {
         if (in_array($fieldInfo['DATA_TYPE'], $allow)) {
             $field = Phprojekt_ActiveRecord_Abstract::convertVarFromSql($field);
             $data[$field] = $object->{$field};
         }
     }
     return $data;
 }
Example #4
0
 /**
  * Delete all the files uploaded in the upload fields.
  *
  * @return void
  */
 public function deleteUploadFiles()
 {
     // Is there is any upload file, -> delete the files from the server
     $fields = $this->getInformation()->getInfo(Phprojekt_ModelInformation_Default::ORDERING_FORM, Phprojekt_DatabaseManager::COLUMN_NAME);
     foreach ($fields as $field) {
         $field = Phprojekt_ActiveRecord_Abstract::convertVarFromSql($field);
         if ($this->getInformation()->getType($field) == 'upload') {
             $filesField = $this->{$field};
             $files = explode('||', $filesField);
             foreach ($files as $file) {
                 $md5Name = substr($file, 0, strpos($file, '|'));
                 $fileAbsolutePath = Phprojekt::getInstance()->getConfig()->uploadPath . $md5Name;
                 if (!empty($md5Name) && file_exists($fileAbsolutePath)) {
                     unlink($fileAbsolutePath);
                 }
             }
         }
     }
 }
Example #5
0
 /**
  * Return an array with the definitions of the field
  * from the databasemanager and the module table itself.
  *
  * The length don't work from int field types.
  *
  * @return array Array with fields definitions.
  */
 public function getDataDefinition()
 {
     $fields = $this->_getFields('form_position', true);
     $data = array();
     $i = 0;
     if (null !== $this->_model) {
         $info = $this->_model->info();
         foreach ($fields as $field) {
             $data[$i]['tableName'] = ucfirst($info['name']);
             while ($field->valid()) {
                 $key = Phprojekt_ActiveRecord_Abstract::convertVarFromSql($field->key());
                 if ($key != 'tableName') {
                     $value = $field->{$key};
                     if (is_numeric($value)) {
                         $data[$i][$key] = (int) $value;
                     } else {
                         if (is_scalar($value)) {
                             $data[$i][$key] = $value;
                         } else {
                             if ($field->isInteger) {
                                 $data[$i][$key] = (int) $value;
                             } else {
                                 $data[$i][$key] = (string) $value;
                             }
                         }
                     }
                 }
                 $field->next();
             }
             $index = self::convertTableField($field->tableField);
             $data[$i]['tableType'] = $info['metadata'][$index]['DATA_TYPE'];
             if (null === $info['metadata'][$index]['LENGTH']) {
                 switch ($info['metadata'][$index]['DATA_TYPE']) {
                     case 'int':
                         $data[$i]['tableLength'] = 11;
                         break;
                     default:
                         $data[$i]['tableLength'] = 255;
                         break;
                 }
             } else {
                 $data[$i]['tableLength'] = $info['metadata'][$index]['LENGTH'];
             }
             $i++;
         }
     }
     return $data;
 }
Example #6
0
 /**
  * Try to receive a tree/subtree from the database using the
  * active record object to get the name of the tree table.
  * If the requested id is not set using the constructor this method
  * usually fails throwing an exception.
  *
  * @param Phprojekt_Filter_Interface $filter A filter to chain.
  *
  * @throws Phprojekt_Tree_Node_Exception If no id was requested (see constructor)
  *
  * @return Phprojekt_Tree_Node_Database An instance of Phprojekt_Tree_Node_Database.
  */
 public function setup(Phprojekt_Filter_Abstract $filter = null)
 {
     // @todo: fix this, must be possible with requestid === null
     if (null === $this->_requestedId) {
         throw new Phprojekt_Tree_Node_Exception('You have to set a requested treeid in the constructor');
     }
     $cache = Phprojekt::getInstance()->getCache();
     if ($this->_requestedId == 0) {
         return $this;
     } else {
         if ($this->_requestedId > 1) {
             if (!($object = $cache->load(self::CACHE_NAME))) {
                 $tree = new Phprojekt_Tree_Node_Database($this->_activeRecord, 1);
                 $object = $tree->setup();
             }
             $tree = $object->getNodeById($this->_requestedId);
             if (null === $tree) {
                 throw new Phprojekt_Tree_Node_Exception('Requested node not found');
             }
             $tree->_parentNode = null;
             return $this->applyRights($tree);
         } else {
             if (!($object = $cache->load(self::CACHE_NAME))) {
                 $database = $this->getActiveRecord()->getAdapter();
                 $table = $this->getActiveRecord()->getTableName();
                 $select = $database->select();
                 $select->from($table, 'path')->where(sprintf('id = %d', (int) $this->_requestedId))->limit(1);
                 if (null !== $filter) {
                     $filter->filter($select, $this->getActiveRecord()->getAdapter());
                 }
                 $rootPath = $database->fetchOne($select);
                 if (null === $rootPath) {
                     throw new Phprojekt_Tree_Node_Exception('Requested node not found');
                 }
                 // Get all the projects
                 $where = sprintf("(%s OR id = %d)", $database->quoteInto("path LIKE ?", $rootPath . '%'), (int) $this->id);
                 $select = $database->select();
                 $select->from($table)->where($where)->order('path');
                 $treeData = $select->query()->fetchAll(Zend_Db::FETCH_CLASS);
                 foreach ($treeData as $index => $record) {
                     foreach ($record as $key => $value) {
                         $newKey = Phprojekt_ActiveRecord_Abstract::convertVarFromSql($key);
                         $treeData[$index]->{$newKey} = $value;
                     }
                 }
                 foreach ($treeData as $record) {
                     $node = null;
                     if ($record->id == $this->_requestedId) {
                         $node = $this;
                         $this->_activeRecord = $record;
                     } elseif (array_key_exists($record->projectId, $this->_index)) {
                         $node = new Phprojekt_Tree_Node_Database($record);
                         $this->_index[$record->projectId]->appendNode($node);
                     }
                     if (null !== $node) {
                         $this->_index[$node->id] = $node;
                     }
                 }
                 $object = $this;
                 $cache->save($this, self::CACHE_NAME);
                 // Delete the session for re-calculate the rights
                 $sessionName = 'Phprojekt_Tree_Node_Database-applyRights';
                 $rightsNamespace = new Zend_Session_Namespace($sessionName);
                 $rightsNamespace->unsetAll();
             }
         }
     }
     return $this->applyRights($object);
 }
Example #7
0
 /**
  * Try to receive a tree/subtree from the database using the
  * active record object to get the name of the tree table.
  * If the requested id is not set using the constructor this method
  * usually fails throwing an exception.
  *
  * @param Phprojekt_Filter_Interface $filter A filter to chain.
  *
  * @throws Phprojekt_Tree_Node_Exception If no id was requested (see constructor)
  *
  * @return Phprojekt_Tree_Node_Database An instance of Phprojekt_Tree_Node_Database.
  */
 public function setup(Phprojekt_Filter_Abstract $filter = null)
 {
     // @todo: fix this, must be possible with requestid === null
     if (null === $this->_requestedId) {
         throw new Phprojekt_Tree_Node_Exception('You have to set a requested treeid in the constructor');
     }
     if ($this->_requestedId == 0) {
         return $this;
     } else {
         $database = $this->getActiveRecord()->getAdapter();
         $table = $this->getActiveRecord()->getTableName();
         $select = $database->select();
         $select->from(array('t' => $table), array())->join(array('tt' => $table), sprintf('t.id = %d AND (tt.path like CONCAT(t.path, t.id, "/%%") OR tt.id = t.id)', (int) $this->_requestedId), '*')->order('path')->order('id');
         if (null !== $filter) {
             $filter->filter($select, 'tt');
         }
         $treeData = $select->query()->fetchAll(Zend_Db::FETCH_CLASS);
         foreach ($treeData as $index => $record) {
             foreach ($record as $key => $value) {
                 $newKey = Phprojekt_ActiveRecord_Abstract::convertVarFromSql($key);
                 $treeData[$index]->{$newKey} = $value;
             }
         }
         foreach ($treeData as $record) {
             $node = null;
             if ($record->id == $this->_requestedId) {
                 $node = $this;
                 $this->_activeRecord = $record;
             } elseif (array_key_exists($record->projectId, $this->_index)) {
                 $node = new Phprojekt_Tree_Node_Database($record);
                 $this->_index[$record->projectId]->appendNode($node);
             }
             if (null !== $node) {
                 $this->_index[$node->id] = $node;
             }
         }
         $object = $this;
     }
     return $this->applyRights($object);
 }