protected function addIncludes(&$script) { if (!DataModelBuilder::getBuildProperty('builderAddIncludes')) { return; } parent::addIncludes($script); }
/** * @see Platform::supportsNativeDeleteTrigger() */ public function supportsNativeDeleteTrigger() { $usingInnoDB = false; if (class_exists('DataModelBuilder', false)) { $usingInnoDB = strtolower(DataModelBuilder::getBuildProperty('mysqlTableType')) == 'innodb'; } return $usingInnoDB || false; }
protected function addDoInsert(&$script) { $tmp = ''; parent::addDoInsert($tmp); if (DataModelBuilder::getBuildProperty('builderAddBehaviors')) { // add sfMixer call $pre_mixer_script = "\n\n foreach (sfMixer::getCallables('{$this->getClassname()}:doInsert:pre') as \$callable)\n {\n \$ret = call_user_func(\$callable, '{$this->getClassname()}', \$values, \$con);\n if (false !== \$ret)\n {\n return \$ret;\n }\n }\n\n"; $post_mixer_script = "\n foreach (sfMixer::getCallables('{$this->getClassname()}:doInsert:post') as \$callable)\n {\n call_user_func(\$callable, '{$this->getClassname()}', \$values, \$con, \$pk);\n }\n\n return"; $tmp = preg_replace('/{/', '{' . $pre_mixer_script, $tmp, 1); $tmp = preg_replace("/\t\treturn/", "\t\t" . $post_mixer_script, $tmp, 1); } $script .= $tmp; }
protected function addSave(&$script) { $tmp = ''; parent::addSave($tmp); // add support for created_(at|on) and updated_(at|on) columns $date_script = ''; $updated = false; $created = false; foreach ($this->getTable()->getColumns() as $col) { $clo = strtolower($col->getName()); if (!$updated && in_array($clo, array('updated_at', 'updated_on'))) { $updated = true; $date_script .= "\n if (\$this->isModified() && !\$this->isColumnModified(" . $this->getColumnConstant($col) . "))\n {\n \$this->set" . $col->getPhpName() . "(time());\n }\n"; } else { if (!$created && in_array($clo, array('created_at', 'created_on'))) { $created = true; $date_script .= "\n if (\$this->isNew() && !\$this->isColumnModified(" . $this->getColumnConstant($col) . "))\n {\n \$this->set" . $col->getPhpName() . "(time());\n }\n"; } } } $tmp = preg_replace('/{/', '{' . $date_script, $tmp, 1); if (DataModelBuilder::getBuildProperty('builderAddBehaviors')) { // add sfMixer call $pre_mixer_script = "\n\n foreach (sfMixer::getCallables('{$this->getClassname()}:save:pre') as \$callable)\n {\n \$affectedRows = call_user_func(\$callable, \$this, \$con);\n if (is_int(\$affectedRows))\n {\n return \$affectedRows;\n }\n }\n\n"; $post_mixer_script = <<<EOF foreach (sfMixer::getCallables('{$this->getClassname()}:save:post') as \$callable) { call_user_func(\$callable, \$this, \$con, \$affectedRows); } EOF; $tmp = preg_replace('/{/', '{' . $pre_mixer_script, $tmp, 1); $tmp = preg_replace('/(\\$con\\->commit\\(\\);)/', '$1' . $post_mixer_script, $tmp); } // update current script $script .= $tmp; }
/** * Adds the doCount() method. * @param string &$script The script will be modified in this method. */ protected function addDoCount(&$script) { $script .= "\n\t/**\n\t * Returns the number of rows matching criteria.\n\t *\n\t * @param Criteria \$criteria\n\t * @param boolean \$distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.\n\t * @param PropelPDO \$con\n\t * @return int Number of matching rows.\n\t */\n\tpublic static function doCount(Criteria \$criteria, \$distinct = false, PropelPDO \$con = null)\n\t{\n\t\t// we may modify criteria, so copy it first\n\t\t\$criteria = clone \$criteria;\n\n\t\t// We need to set the primary table name, since in the case that there are no WHERE columns\n\t\t// it will be impossible for the BasePeer::createSelectSql() method to determine which\n\t\t// tables go into the FROM clause.\n\t\t\$criteria->setPrimaryTableName(" . $this->getPeerClassname() . "::TABLE_NAME);\n\n\t\tif (\$distinct && !in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {\n\t\t\t\$criteria->setDistinct();\n\t\t}\n\n\t\tif (!\$criteria->hasSelectClause()) {\n\t\t\t" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);\n\t\t}\n\n\t\t\$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count\n\t\t\$criteria->setDbName(self::DATABASE_NAME); // Set the correct dbName\n\n\t\tif (\$con === null) {\n\t\t\t\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);\n\t\t}\n"; if (DataModelBuilder::getBuildProperty('builderAddBehaviors')) { $script .= "\n\n foreach (sfMixer::getCallables('{$this->getClassname()}:doCount:doCount') as \$callable)\n {\n call_user_func(\$callable, '{$this->getClassname()}', \$criteria, \$con);\n }\n\n"; } $script .= "\n\t\t// BasePeer returns a PDOStatement\n\t\t\$stmt = " . $this->basePeerClassname . "::doCount(\$criteria, \$con);\n\n\t\tif (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {\n\t\t\t\$count = (int) \$row[0];\n\t\t} else {\n\t\t\t\$count = 0; // no rows returned; we infer that means 0 matches.\n\t\t}\n\t\t\$stmt->closeCursor();\n\t\treturn \$count;\n\t}"; }