コード例 #1
0
ファイル: Secretkey.php プロジェクト: kokkez/shineisp
 public function __construct(Doctrine_Table $table, $fieldName)
 {
     $this->_table = $table;
     $columnList = $this->_table->getColumnNames();
     //Check if the identity and credential are one of the column names...
     if (!in_array($fieldName, $columnList)) {
         throw new Zend_Auth_Adapter_Exception("Invalid Column names are given as '{$fieldName}'");
     }
     $this->_fieldName = $fieldName;
 }
 public function generateClassFromTable(Doctrine_Table $table)
 {
     $definition = array();
     $definition['columns'] = $table->getColumns();
     $definition['tableName'] = $table->getTableName();
     $definition['actAs'] = $table->getTemplates();
     $definition['generate_once'] = true;
     $generatedclass = $this->generateClass($definition);
     Doctrine::loadModels(sfConfig::get('sf_lib_dir') . '/model/doctrine/opCommunityTopicPlugin/base/');
     return $generatedclass;
 }
コード例 #3
0
ファイル: Doctrine.php プロジェクト: kokkez/shineisp
 public function __construct(Doctrine_Table $table, $identityCol, $credentialCol)
 {
     $this->_table = $table;
     $columnList = $this->_table->getColumnNames();
     //Check if the identity and credential are one of the column names...
     if (!in_array($identityCol, $columnList) || !in_array($credentialCol, $columnList)) {
         throw new Zend_Auth_Adapter_Exception("Invalid Column names are given as '{$identityCol}' and '{$credentialCol}'");
     }
     $this->_credentialCol = $credentialCol;
     //Assign the column names...
     $this->_identityCol = $identityCol;
 }
コード例 #4
0
ファイル: File.php プロジェクト: kirvin/the-nerdery
 /**
  * constructor
  *
  * @param array $options    an array of plugin options
  */
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     if (!isset($this->_options['resource'])) {
         $table = new Doctrine_Table('File', Doctrine_Manager::connection());
         $table->setColumn('url', 'string', 255, array('primary' => true));
     }
     if (empty($this->_options['fields'])) {
         $this->_options['fields'] = array('url', 'content');
     }
     $this->initialize($table);
 }
コード例 #5
0
ファイル: Tree.php プロジェクト: densem-2013/exikom
 /**
  * constructor, creates tree with reference to table and any options
  *
  * @param object $table                     instance of Doctrine_Table
  * @param array $options                    options
  */
 public function __construct(Doctrine_Table $table, $options)
 {
     $this->table = $table;
     $this->options = $options;
     $this->_baseComponent = $table->getComponentName();
     $class = $this->_baseComponent;
     if ($table->getOption('inheritanceMap')) {
         $subclasses = $table->getOption('subclasses');
         while (in_array($class, $subclasses)) {
             $class = get_parent_class($class);
         }
         $this->_baseComponent = $class;
     }
     //echo $this->_baseComponent;
 }
コード例 #6
0
 /**
  * Return a query object, creating a new one if needed.
  *
  * @param Doctrine_Query $query
  * @return Doctrine_Query
  */
 public function getQuery(Doctrine_Query $query = null)
 {
     if (is_null($query)) {
         $query = parent::createQuery('variation');
     }
     return $query;
 }
コード例 #7
0
ファイル: RecordDriver.php プロジェクト: kirvin/the-nerdery
 /**
  * isIdentifiable
  * returns whether or not a given data row is identifiable (it contains
  * all primary key fields specified in the second argument)
  *
  * @param array $row
  * @param Doctrine_Table $table
  * @return boolean
  */
 public function isIdentifiable(array $row, Doctrine_Table $table)
 {
     $primaryKeys = $table->getIdentifierColumnNames();
     if (is_array($primaryKeys)) {
         foreach ($primaryKeys as $id) {
             if (!isset($row[$id])) {
                 return false;
             }
         }
     } else {
         if (!isset($row[$primaryKeys])) {
             return false;
         }
     }
     return true;
 }
コード例 #8
0
ファイル: Collection.php プロジェクト: nationalfield/symfony
    /**
     * Deletes all records from this collection
     *
     * @return Doctrine_Collection
     */
    public function delete(Doctrine_Connection $conn = null, $clearColl = true)
    {
        if ($conn == null) {
            $conn = $this->_table->getConnection();
        }

        try {
            $conn->beginInternalTransaction();
            $conn->transaction->addCollection($this);

            foreach ($this as $key => $record) {
                $record->delete($conn);
            }

            $conn->commit();
        } catch (Exception $e) {
            $conn->rollback();
            throw $e;
        }

        if ($clearColl) {
            $this->clear();
        }

        return $this;
    }
コード例 #9
0
 /**
  * Write Event to database
  *
  * @param  array  $event
  */
 public function _write($event)
 {
     $entry = $this->_table->create(array());
     foreach ($this->_columnMap as $eventIndex => $tableColumn) {
         $entry->{$tableColumn} = $event[$eventIndex];
     }
     $entry->save();
 }
コード例 #10
0
 public function createQuery($alias = '')
 {
     //By default, collection is ordered by length descending.  This prevents word overlap
     // ex: 'my word' will match before 'word'.  More "specific" Hyperwords match first
     $q = parent::createQuery($alias);
     $q->select('*, LENGTH(name) as length')->orderBy('length DESC');
     return $q;
 }
コード例 #11
0
ファイル: Abstract.php プロジェクト: ajbrown/bitnotion
 /**
  *
  *@throws Doctrine_Connection_Exception    if there are no opened connections
  *@param Doctrine_Connection $conn         the connection associated with this table
  */
 public function __construct(Doctrine_Connection $conn = null)
 {
     if ($conn === null) {
         $conn = Doctrine_Manager::connection();
     }
     $name = str_replace('App_Table_', '', get_class($this));
     parent::__construct($name, $conn, true);
 }
コード例 #12
0
 /**
  * Our index action, show a lab.
  */
 public function indexAction()
 {
     $this->view->headScript()->appendFile("/js/taffydb/taffy.js")->appendFile("/js/labs/views/task.js")->appendFile("/js/labs/models/task.js")->appendFile("/js/labs/controllers/add_task.js")->appendFile("/js/labs/controllers/task_list.js");
     // Check for a code
     if (!$this->_request->has("code")) {
         throw new Exception(self::ERROR_NO_CODE, 404);
     }
     // get the passed code
     $code = $this->_request->getParam("code");
     $lab = $this->db->findOneByCode($code);
     // check if the code is valid
     if (!$lab instanceof App_Db_Lab) {
         throw new Exception(self::ERROR_INVALID_CODE, 404);
     }
     $this->view->lab = $lab;
     $this->view->headTitle($lab->name);
 }
コード例 #13
0
ファイル: Where.php プロジェクト: amitesh-singh/Enlightenment
 public function parseValue($value, Doctrine_Table $table = null, $field = null)
 {
     $conn = $this->query->getConnection();
     if (substr($value, 0, 1) == '(') {
         // trim brackets
         $trimmed = $this->_tokenizer->bracketTrim($value);
         if (substr($trimmed, 0, 4) == 'FROM' || substr($trimmed, 0, 6) == 'SELECT') {
             // subquery found
             $q = new Doctrine_Query();
             $value = '(' . $this->query->createSubquery()->parseQuery($trimmed, false)->getQuery() . ')';
         } elseif (substr($trimmed, 0, 4) == 'SQL:') {
             $value = '(' . substr($trimmed, 4) . ')';
         } else {
             // simple in expression found
             $e = $this->_tokenizer->sqlExplode($trimmed, ',');
             $value = array();
             $index = false;
             foreach ($e as $part) {
                 if (isset($table) && isset($field)) {
                     $index = $table->enumIndex($field, trim($part, "'"));
                     if (false !== $index && $conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
                         $index = $conn->quote($index, 'text');
                     }
                 }
                 if ($index !== false) {
                     $value[] = $index;
                 } else {
                     $value[] = $this->parseLiteralValue($part);
                 }
             }
             $value = '(' . implode(', ', $value) . ')';
         }
     } else {
         if (substr($value, 0, 1) == ':' || $value === '?') {
             // placeholder found
             if (isset($table) && isset($field) && $table->getTypeOf($field) == 'enum') {
                 $this->query->addEnumParam($value, $table, $field);
             } else {
                 $this->query->addEnumParam($value, null, null);
             }
         } else {
             $enumIndex = false;
             if (isset($table) && isset($field)) {
                 // check if value is enumerated value
                 $enumIndex = $table->enumIndex($field, trim($value, "'"));
                 if (false !== $enumIndex && $conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
                     $enumIndex = $conn->quote($enumIndex, 'text');
                 }
             }
             if ($enumIndex !== false) {
                 $value = $enumIndex;
             } else {
                 $value = $this->parseLiteralValue($value);
             }
         }
     }
     return $value;
 }
コード例 #14
0
 /**
  * Before returning the exportable-version of this table, unset any foreign
  * keys that had the option "export => false".
  *
  * @param bool    $parseForeignKeys
  * @return array
  */
 public function getExportableFormat($parseForeignKeys = true)
 {
     $data = parent::getExportableFormat($parseForeignKeys);
     // unset any fk's that we shouldn't export
     foreach ($this->no_export as $rel_alias) {
         $key_name = $this->getRelation($rel_alias)->getForeignKeyName();
         unset($data['options']['foreignKeys'][$key_name]);
     }
     return $data;
 }
コード例 #15
0
 /**
  * get product object of class depending on object properties itself
  * 
  * @see vendor/doctrine/Doctrine/Doctrine_Table::getRecord()
  * 
  * @return tpyProduct
  */
 public function getRecord()
 {
     $basic_product = parent::getRecord();
     if (0 == strlen($basic_product->getClassName()) or $basic_product->getClassName() == get_class($basic_product)) {
         return $basic_product;
     }
     $class_name = $basic_product->getClassName();
     $special_product = new $class_name($this, false);
     $special_product->setDoctrineRecord($basic_product);
     return $special_product;
 }
コード例 #16
0
ファイル: DoctrineForm.php プロジェクト: abtris/zfcore
 /**
  * Returns all un-ignored relations
  * @return array
  */
 protected function _getRelations()
 {
     $relations = array();
     foreach ($this->_table->getRelations() as $name => $definition) {
         if (in_array($definition->getLocal(), $this->_ignoreColumns) || $this->_generateManyFields == false && $definition->getType() == Doctrine_Relation::MANY) {
             continue;
         }
         $relations[$name] = $definition;
     }
     return $relations;
 }
コード例 #17
0
ファイル: EntityTable.class.php プロジェクト: silky/littlesis
 public function getRelation($alias, $recursive = true)
 {
     if ($this->hasRelation($alias)) {
         return parent::getRelation($alias, $recursive);
     }
     foreach (ExtensionDefinitionTable::$extensionNamesWithFields as $extension) {
         if (Doctrine::getTable($extension)->hasRelation($alias)) {
             return Doctrine::getTable($extension)->getRelation($alias, $recursive);
         }
     }
     return parent::getRelation($alias, $recursive);
 }
コード例 #18
0
ファイル: Check.php プロジェクト: snouhaud/camptocamp.org
 public function parseFunction($dql)
 {
     if (($pos = strpos($dql, '(')) !== false) {
         $func = substr($dql, 0, $pos);
         $value = substr($dql, $pos + 1, -1);
         $expr = $this->table->getConnection()->expression;
         if (!method_exists($expr, $func)) {
             throw new Doctrine_Query_Exception('Unknown function ' . $func);
         }
         $func = $expr->{$func}($value);
     }
     return $func;
 }
コード例 #19
0
 /**
  * this is to retrieve an array of Key values of a Property whose name starts similarly
  *
  * $arr = PropertyTable::getKeysLike('tax'); $arr = PropertyTable::getKeysLike('serie');
  * @author Leo
  **/
 public static function getKeysLike($key)
 {
     $arr = array();
     $c = new Criteria();
     $c->add(parent::KEY, '%' . $key . '_%', CRITERIA::LIKE);
     $obj = parent::doSelect($c);
     foreach ($obj as $o) {
         foreach ($o->getValue() as $vk => $vv) {
             $arr[$vk] = $vv;
         }
     }
     return $arr;
 }
コード例 #20
0
ファイル: Lab.php プロジェクト: samuel-mccallum/Task-Lab
 /**
  * Create a new lab
  * @param <type> $name
  * @return <type>
  */
 public function create($name)
 {
     if ($name == "") {
         throw new Exception(self::ERROR_INVALID_NAME);
     }
     $code_generator = new App_Value_Code();
     do {
         $code = $code_generator->get();
     } while ($this->db->findByCode($code)->count() != 0);
     $lab = $this->db->create();
     $lab->name = $name;
     $lab->code = $code;
     if ($lab->isValid()) {
         try {
             $lab->save();
         } catch (Exception $e) {
             throw new Exception(self::ERROR_NOT_SAVED);
         }
     } else {
         throw new Exception(self::ERROR_NOT_VALID . $lab->getErrorStackAsString());
     }
     return $lab->toArray();
 }
コード例 #21
0
ファイル: Collection.php プロジェクト: kirvin/the-nerdery
 /**
  * delete
  * single shot delete
  * deletes all records from this collection
  * and uses only one database query to perform this operation
  *
  * @return Doctrine_Collection
  */
 public function delete(Doctrine_Connection $conn = null)
 {
     if ($conn == null) {
         $conn = $this->_table->getConnection();
     }
     $conn->beginTransaction();
     $conn->transaction->addCollection($this);
     foreach ($this as $key => $record) {
         $record->delete($conn);
     }
     $conn->commit();
     $this->data = array();
     return $this;
 }
コード例 #22
0
 /**
  * Returns true if this column is a foreign key and false if it is not
  *
  * @return boolean $isForeignKey
  */
 public function isForeignKey()
 {
     if (isset($this->foreignClassName)) {
         return true;
     }
     if ($this->isPrimaryKey()) {
         return false;
     }
     foreach ($this->table->getRelations() as $relation) {
         if (strtolower($relation['local']) == strtolower($this->name)) {
             $this->foreignClassName = $relation['class'];
             return true;
         }
     }
     return false;
 }
コード例 #23
0
ファイル: Doctrine.php プロジェクト: BGCX262/zym-svn-to-git
 /**
  * Write a message to the log.
  *
  * @param  array  $event  event data
  * @return void
  */
 protected function _write($event)
 {
     if ($this->_table === null) {
         throw new Zym_Log_Exception('Database adapter instance has been removed by shutdown');
     }
     if (!$this->_columnMap) {
         $dataToInsert = $event;
     } else {
         $dataToInsert = array();
         foreach ($this->_columnMap as $columnName => $fieldKey) {
             $dataToInsert[$columnName] = $event[$fieldKey];
         }
     }
     $record = $this->_table->create($dataToInsert);
     $record->save();
 }
コード例 #24
0
 /**
  * @covers Robo47_Log_Writer_DoctrineTable::_write
  */
 public function testWriteWithChangedColumnMap()
 {
     $mapping = array('message' => 'foo', 'priority' => 'baa', 'category' => 'blub', 'timestamp' => 'baafoo');
     $this->_writer->setTable($this->_table2);
     $this->_writer->setColumnMap($mapping);
     $this->assertEquals(0, $this->_table2->count());
     $date = date('c');
     $event = array('message' => 'Foo', 'priority' => 0, 'category' => 'bla', 'timestamp' => $date);
     $this->_writer->write($event);
     $this->assertEquals(1, $this->_table2->count());
     $entry = $this->_table2->createQuery()->select()->execute()->getFirst();
     $this->assertEquals($event['message'], $entry->foo);
     $this->assertEquals($event['priority'], $entry->baa);
     $this->assertEquals($event['category'], $entry->blub);
     $this->assertEquals($event['timestamp'], $entry->baafoo);
 }
コード例 #25
0
ファイル: Doctrine.php プロジェクト: lciolecki/zf-doctrine
 /**
  * Return relations as an array
  *
  * Array must contain 'type' for relation type, 'id' for the name
  * of the PK column of the related table, 'model' for the related class
  * name, 'notnull' for nullability. 'local' for the name of the local column
  * Key must be the alias of the relation column
  *
  * @return array
  */
 public function getManyRelations()
 {
     $rels = $this->_table->getRelations();
     $relations = array();
     foreach ($rels as $rel) {
         $relation = array();
         if ($rel->getType() == Doctrine_Relation::MANY && isset($rel['refTable'])) {
             $relation['id'] = $rel->getTable()->getIdentifier();
             $relation['model'] = $rel->getClass();
             $relation['local'] = $rel->getLocal();
             $definition = $this->_table->getColumnDefinition($rel->getLocal());
             $relation['notnull'] = isset($definition['notnull']) ? $definition['notnull'] : false;
             $relations[$rel->getAlias()] = $relation;
         }
     }
     return $relations;
 }
コード例 #26
0
ファイル: Query.php プロジェクト: JimmyVB/Symfony-v1.2
 public function parseTerm($term)
 {
     $negation = false;
     if (strpos($term, "'") === false) {
         $where = $this->parseWord($term);
     } else {
         $term = trim($term, "' ");
         $terms = $this->_tokenizer->quoteExplode($term);
         $where = $this->parseWord($terms[0]);
         foreach ($terms as $k => $word) {
             if ($k === 0) {
                 continue;
             }
             $where .= ' AND (position + ' . $k . ') = (SELECT position FROM ' . $this->_table->getTableName() . ' WHERE ' . $this->parseWord($word) . ')';
         }
     }
     return $where;
 }
コード例 #27
0
 /**
  * Returns true if this column is a foreign key and false if it is not
  *
  * @return boolean $isForeignKey
  */
 public function isForeignKey()
 {
     if (isset($this->foreignClassName)) {
         return true;
     }
     if ($this->isPrimaryKey()) {
         return false;
     }
     foreach ($this->table->getRelations() as $relation) {
         $local = (array) $relation['local'];
         $local = array_map('strtolower', $local);
         if (in_array(strtolower($this->name), $local)) {
             $this->foreignClassName = $relation['class'];
             return true;
         }
     }
     return false;
 }
コード例 #28
0
 public function buildIntegrityRelations(Doctrine_Table $table, &$aliases, &$fields, &$indexes, &$components)
 {
     $deleteActions = Doctrine_Manager::getInstance()->getDeleteActions($table->getComponentName());
     foreach ($table->getRelations() as $relation) {
         $componentName = $relation->getTable()->getComponentName();
         if (in_array($componentName, $components)) {
             continue;
         }
         $components[] = $componentName;
         $alias = strtolower(substr($relation->getAlias(), 0, 1));
         if (!isset($indexes[$alias])) {
             $indexes[$alias] = 1;
         }
         if (isset($deleteActions[$componentName])) {
             if (isset($aliases[$alias])) {
                 $alias = $alias . ++$indexes[$alias];
             }
             $aliases[$alias] = $relation->getAlias();
             if ($deleteActions[$componentName] === 'SET NULL') {
                 if ($relation instanceof Doctrine_Relation_ForeignKey) {
                     foreach ((array) $relation->getForeign() as $foreign) {
                         $fields .= ', ' . $alias . '.' . $foreign;
                     }
                 } elseif ($relation instanceof Doctrine_Relation_LocalKey) {
                     foreach ((array) $relation->getLocal() as $foreign) {
                         $fields .= ', ' . $alias . '.' . $foreign;
                     }
                 }
             }
             foreach ((array) $relation->getTable()->getIdentifier() as $id) {
                 $fields .= ', ' . $alias . '.' . $id;
             }
             if ($deleteActions[$componentName] === 'CASCADE') {
                 $this->buildIntegrityRelations($relation->getTable(), $aliases, $fields, $indexes, $components);
             }
         }
     }
 }
コード例 #29
0
 /**
  * Collections tag name
  *
  * @return string
  */
 public static function obtainCollectionName(Doctrine_Table $table)
 {
     return self::getBaseClassName($table->getClassnameToReturn());
 }
コード例 #30
0
 /**
  * addTable
  * adds a Doctrine_Table object into connection registry
  *
  * @param $table                a Doctrine_Table object to be added into registry
  * @return boolean
  */
 public function addTable(Doctrine_Table $table)
 {
     $name = $table->getComponentName();
     if (isset($this->tables[$name])) {
         return false;
     }
     $this->tables[$name] = $table;
     return true;
 }