当前位置: 首页>>代码示例>>PHP>>正文


PHP Model::getClassFromTable方法代码示例

本文整理汇总了PHP中Model::getClassFromTable方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getClassFromTable方法的具体用法?PHP Model::getClassFromTable怎么用?PHP Model::getClassFromTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Model的用法示例。


在下文中一共展示了Model::getClassFromTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: deleteDataRecord

 /**
  * @param $dc
  */
 public static function deleteDataRecord($dc)
 {
     // If this is not the backend than return
     if (TL_MODE != 'BE') {
         return;
     }
     // Check if there is an active record
     if ($dc instanceof \DataContainer && $dc->activeRecord) {
         $intId = $dc->activeRecord->id;
         $strTable = $dc->table;
         $strModel = '\\' . \Model::getClassFromTable($strTable);
         $objTranslationController = new \TranslationController();
         // Return if the class does not exist (#9 thanks to tsarma)
         if (!class_exists($strModel)) {
             return;
         }
         // Get object from model
         $objModel = $strModel::findByPk($intId);
         if ($objModel !== null) {
             $arrData = $objModel->row();
             if (is_array($arrData) && count($arrData) > 0) {
                 // Load current data container
                 $objTranslationController->loadDataContainer($strTable);
                 // Get tl_undo data
                 $objUndo = \Database::getInstance()->prepare("SELECT * FROM tl_undo WHERE fromTable=? ORDER BY id DESC")->limit(1)->execute($dc->table);
                 $arrSet = $objUndo->row();
                 // Deserialize tl_undo data
                 $arrSet['data'] = deserialize($arrSet['data']);
                 foreach ($arrData as $strField => $varValue) {
                     switch ($GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['inputType']) {
                         case 'TranslationInputUnit':
                         case 'TranslationTextArea':
                         case 'TranslationTextField':
                             // Get translation values
                             $objTranslation = \TranslationFieldsModel::findByFid($varValue);
                             if ($objTranslation !== null) {
                                 while ($objTranslation->next()) {
                                     $t = \TranslationFieldsModel::getTable();
                                     // Add cross table record to undo data
                                     $arrSet['data'][$t][] = $objTranslation->row();
                                     // Delete translation
                                     $objTranslation->delete();
                                 }
                             }
                             break;
                     }
                 }
                 // Serialize tl_undo data
                 $arrSet['data'] = serialize($arrSet['data']);
                 // Update tl_undo
                 \Database::getInstance()->prepare("UPDATE tl_undo %s WHERE id=?")->set($arrSet)->execute($objUndo->id);
             }
         }
     }
 }
开发者ID:craffft,项目名称:contao-translation-fields,代码行数:58,代码来源:TranslationFieldsBackendHelper.php

示例2: save

 /**
  * @param $varValue
  * @param \DataContainer $dc
  * @return string
  */
 public static function save($varValue, \DataContainer $dc)
 {
     $arrItems = deserialize($varValue);
     if (!is_array($arrItems)) {
         $arrItems = array();
     }
     $dca = $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field];
     $strModel = \Model::getClassFromTable($dca['crossTable']);
     self::removeOldItems($strModel, $arrItems, $dc->id, $dca['crossCurrentKey'], $dca['crossForeignKey']);
     self::addNewItems($strModel, $arrItems, $dc->id, $dca['crossCurrentKey'], $dca['crossForeignKey']);
     return '';
 }
开发者ID:Craffft,项目名称:crosstabs-bundle,代码行数:17,代码来源:TableLookupWizard.php

示例3: onSubmitCallback

 protected function onSubmitCallback(\DataContainer $objDc)
 {
     parent::onSubmitCallback($objDc);
     if ($this->publishOnValid) {
         $strPublishedField = $this->publishedField;
         if ($this->publishedField) {
             $strModelClass = \Model::getClassFromTable($this->strTable);
             $objInstance = $strModelClass::findByPk($objDc->objActiveRecord->id);
             $objInstance->{$strPublishedField} = $this->invertPublishedField ? '' : 1;
             $objInstance->save();
         }
     }
 }
开发者ID:heimrichhannot,项目名称:contao-frontendedit,代码行数:13,代码来源:ValidatorForm.php

示例4: __construct

 /**
  * Initialize the object
  *
  * @param ContentModel|ModuleModel|FormModel $objElement
  * @param string                             $strColumn
  */
 public function __construct($objElement, $strColumn = 'main')
 {
     parent::__construct();
     // Store the parent element (see #4556)
     if ($objElement instanceof Model) {
         $this->objParent = $objElement;
     } elseif ($objElement instanceof Model\Collection) {
         $this->objParent = $objElement->current();
     }
     if ($this->strKey == '' || $this->strTable == '') {
         return;
     }
     /** @var Model $strModelClass */
     $strModelClass = \Model::getClassFromTable($this->strTable);
     // Load the model
     if (class_exists($strModelClass)) {
         $objHybrid = $strModelClass::findByPk($objElement->{$this->strKey});
         if ($objHybrid === null) {
             return;
         }
         $this->objModel = $objHybrid;
     } else {
         $objHybrid = $this->Database->prepare("SELECT * FROM " . $this->strTable . " WHERE id=?")->limit(1)->execute($objElement->{$this->strKey});
         if ($objHybrid->numRows < 1) {
             return;
         }
     }
     $cssID = array();
     $this->arrData = $objHybrid->row();
     // Get the CSS ID from the parent element (!)
     $this->cssID = deserialize($objElement->cssID, true);
     if (isset($objHybrid->attributes)) {
         $cssID = deserialize($objHybrid->attributes, true);
     }
     // Override the CSS ID (see #305)
     if (!empty($this->cssID[0])) {
         $cssID[0] = $this->cssID[0];
     }
     // Merge the CSS classes (see #6011)
     if (!empty($this->cssID[1])) {
         $cssID[1] = trim($cssID[1] . ' ' . $this->cssID[1]);
     }
     $this->cssID = $cssID;
     $this->typePrefix = $objElement->typePrefix;
     $arrHeadline = deserialize($objElement->headline);
     $this->headline = is_array($arrHeadline) ? $arrHeadline['value'] : $arrHeadline;
     $this->hl = is_array($arrHeadline) ? $arrHeadline['unit'] : 'h1';
     $this->strColumn = $strColumn;
 }
开发者ID:Mozan,项目名称:core-bundle,代码行数:55,代码来源:Hybrid.php

示例5: run

 /**
  * run the importer
  * @return bool
  */
 public function run()
 {
     $this->collectItems();
     if ($this->objItems === null) {
         return false;
     }
     $strClass = \Model::getClassFromTable(static::$strTable);
     if (!class_exists($strClass)) {
         return false;
     }
     while ($this->objItems->next()) {
         $objItem = $this->createObjectFromMapping($this->objItems, $strClass);
         $this->createImportMessage($objItem);
     }
     return true;
 }
开发者ID:heimrichhannot,项目名称:contao-newsport,代码行数:20,代码来源:Importer.php

示例6: getParentEntitiesAsOptions

 public static function getParentEntitiesAsOptions(\DataContainer $objDc)
 {
     $arrOptions = array();
     $arrTitleSynonyms = array('title', 'headline', 'name');
     if (($strParentTable = $objDc->activeRecord->parentTable) && ($strClass = \Model::getClassFromTable($strParentTable))) {
         \Controller::loadDataContainer($strParentTable);
         if (($objEntities = $strClass::findAll()) !== null) {
             foreach ($arrTitleSynonyms as $strField) {
                 if (\Database::getInstance()->fieldExists($strField, $strParentTable)) {
                     $arrOptions = $objEntities->fetchEach($strField);
                     asort($arrOptions);
                     break;
                 }
             }
         }
     }
     return $arrOptions;
 }
开发者ID:heimrichhannot,项目名称:contao-entity_lock,代码行数:18,代码来源:tl_entity_lock.php

示例7: deleteCallback

 /**
  * Removes the cross table items from the current deleted left table item
  *
  * @access public
  * @static
  * @param  \DataContainer $dc
  */
 public static function deleteCallback(\DataContainer $dc)
 {
     if (!$dc->activeRecord) {
         return;
     }
     $intId = $dc->activeRecord->id;
     $strTable = $dc->table;
     if (isset($GLOBALS['TL_DCA'][$dc->table]['fields'])) {
         foreach ($GLOBALS['TL_DCA'][$dc->table]['fields'] as $k => $v) {
             if (!isset($v['crossTable']) || !isset($v['crossCurrentKey'])) {
                 continue;
             }
             // Get model name
             $strModel = \Model::getClassFromTable($v['crossTable']);
             // Check if model exists
             if (!class_exists($strModel)) {
                 return;
             }
             // Get model object
             $objModel = $strModel::findBy($v['crossCurrentKey'], $intId);
             if ($objModel !== null) {
                 // Get tl_undo data
                 $objUndo = \Database::getInstance()->prepare("SELECT * FROM tl_undo WHERE fromTable=? ORDER BY id DESC")->limit(1)->execute($dc->table);
                 $arrSet = $objUndo->row();
                 // Deserialize tl_undo data
                 $arrSet['data'] = deserialize($arrSet['data']);
                 while ($objModel->next()) {
                     // Add cross table record to undo data
                     $arrSet['data'][$v['crossTable']][] = $objModel->row();
                     // Delete cross table item
                     $objModel->delete();
                 }
                 // Serialize tl_undo data
                 $arrSet['data'] = serialize($arrSet['data']);
                 // Update tl_undo
                 \Database::getInstance()->prepare("UPDATE tl_undo %s WHERE id=?")->set($arrSet)->execute($objUndo->id);
             }
         }
     }
 }
开发者ID:craffft,项目名称:contao-crosstabs,代码行数:47,代码来源:LeftTable.php

示例8: setAutoPassword

 /**
  * @param null $dc
  * @throws \Exception
  */
 public function setAutoPassword($dc = null)
 {
     // Front end call
     if (!$dc instanceof \DataContainer) {
         return;
     }
     if ($this->isDisabledAccountMail($dc)) {
         return;
     }
     $intId = $dc->id;
     if (\Input::get('act') == 'overrideAll' && \Input::get('fields') && $intId === null) {
         // Define indicator for given or not given password on overrideAll mode
         if (!isset($GLOBALS['ACCOUNTMAIL']['AUTO_PASSWORD'])) {
             $strPassword = $this->getPostPassword();
             $GLOBALS['ACCOUNTMAIL']['AUTO_PASSWORD'] = $strPassword == '' || $strPassword == '*****' ? true : false;
             if ($GLOBALS['ACCOUNTMAIL']['AUTO_PASSWORD'] === true) {
                 // Set password, that no error occurs with "password not set"
                 $strNewPassword = substr(str_shuffle('abcdefghkmnpqrstuvwxyzABCDEFGHKMNOPQRSTUVWXYZ0123456789'), 0, 8);
                 $this->setPostPassword($strNewPassword);
             }
             \Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['pw_changed']);
         }
         return;
     }
     $strPassword = $this->getPostPassword($intId);
     if ($strPassword !== null && $strPassword == '') {
         $strModel = \Model::getClassFromTable($dc->table);
         $objAccount = $strModel::findByPk($intId);
         if ($objAccount !== null) {
             $strNewPassword = substr(str_shuffle('abcdefghkmnpqrstuvwxyzABCDEFGHKMNOPQRSTUVWXYZ0123456789'), 0, 8);
             $this->setPostPassword($strNewPassword, $intId);
             \Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['pw_changed']);
             $objAccount->password = \Encryption::hash($strNewPassword);
             $objAccount->save();
         }
     }
 }
开发者ID:craffft,项目名称:contao-accountmail,代码行数:41,代码来源:Account.php

示例9: __construct

 /**
  * Initialize the object
  * @param object
  * @param string
  */
 public function __construct($objElement, $strColumn = 'main')
 {
     parent::__construct();
     // Store the parent element (see #4556)
     if ($objElement instanceof \Model) {
         $this->objParent = $objElement;
     } elseif ($objElement instanceof \Model\Collection) {
         $this->objParent = $objElement->current();
     }
     if ($this->strKey == '' || $this->strTable == '') {
         return;
     }
     $strModelClass = \Model::getClassFromTable($this->strTable);
     // Load the model
     if (class_exists($strModelClass)) {
         $objHybrid = $strModelClass::findByPk($objElement->{$this->strKey});
         if ($objHybrid === null) {
             return;
         }
         $this->objModel = $objHybrid;
     } else {
         $objHybrid = $this->Database->prepare("SELECT * FROM " . $this->strTable . " WHERE id=?")->limit(1)->execute($objElement->{$this->strKey});
         if ($objHybrid->numRows < 1) {
             return;
         }
     }
     $this->arrData = $objHybrid->row();
     // Get space and CSS ID from the parent element (!)
     $this->space = deserialize($objElement->space);
     $this->cssID = deserialize($objElement->cssID, true);
     $this->typePrefix = $objElement->typePrefix;
     $arrHeadline = deserialize($objElement->headline);
     $this->headline = is_array($arrHeadline) ? $arrHeadline['value'] : $arrHeadline;
     $this->hl = is_array($arrHeadline) ? $arrHeadline['unit'] : 'h1';
     $this->strColumn = $strColumn;
 }
开发者ID:iCodr8,项目名称:core,代码行数:41,代码来源:Hybrid.php

示例10: create

 /**
  * @param \Database\Result|int $result Result object or id
  * @param string $table
  * @param bool $update Update model to current result if model is in the registry
  *
  * @return \Model
  */
 public static function create($result, $table, $update = false)
 {
     $model = null;
     $class = \Model::getClassFromTable($table);
     $id = is_object($result) ? $result->id : $result;
     $cto32 = version_compare(VERSION, '3.2', '>=');
     // Check the registry in Contao 3.2
     if ($cto32) {
         $model = \Model\Registry::getInstance()->fetch($table, $id);
         // model is already in the registry, shall we update the model to the current record?
         // This will affect every reference which uses the model
         // You really have to know what u need - both is dangerous
         if ($model && $update) {
             $model->setRow($result->row());
         }
     }
     // Model is not in the registry
     if (!$model) {
         if (is_object($result)) {
             $model = new $class($result);
         } else {
             // we have to get the result from the db
             $result = \Database::getInstance()->prepare("SELECT * FROM {$table} WHERE id=?")->execute($id);
             if ($result->numRows) {
                 $model = new $class($result);
             } else {
                 $model = new $class();
                 // do not set id if Contao 3.2 is used because a new record is created, so that id is ignored
                 if (!$cto32) {
                     $model->id = $id;
                 }
             }
         }
     }
     return $model;
 }
开发者ID:netzmacht,项目名称:contao-bootstrap,代码行数:43,代码来源:Factory.php

示例11: run

 /**
  * run the importer
  *
  * @return bool
  */
 public function run($dry = false)
 {
     $this->dryRun = $dry;
     $this->collectItems();
     if ($this->objItems === null) {
         return false;
     }
     $strClass = \Model::getClassFromTable($this->dbTargetTable);
     if (!class_exists($strClass)) {
         return false;
     }
     while ($this->objItems->next()) {
         $objItem = $this->createObjectFromMapping($this->objItems, $strClass);
         $this->createImportMessage($objItem);
     }
     // reset the iterator
     $this->objItems->reset();
     $this->runAfterComplete($this->objItems);
     return true;
 }
开发者ID:heimrichhannot,项目名称:contao-entity_import,代码行数:25,代码来源:Importer.php

示例12: initialize

 protected function initialize($blnCreated = false)
 {
     // load the model
     // don't load any class if the form's a filter form -> submission should be used instead
     if ($this->hasDatabaseTable() && !$this->hasNoEntity()) {
         $strModelClass = \Model::getClassFromTable($this->strTable);
     }
     if (class_exists($strModelClass)) {
         if (!$blnCreated && ($objModel = $strModelClass::findByPk($this->intId)) !== null) {
             $this->objActiveRecord = $objModel;
             $this->setMode(FORMHYBRID_MODE_EDIT);
             if ($this->saveToBlob) {
                 $this->loadFromBlob(deserialize($objModel->formHybridBlob, true));
             }
             // redirect on specific field value
             static::doFieldDependentRedirect();
         } else {
             if ($this->objModule !== null && Ajax::isRelated(Form::FORMHYBRID_NAME) !== false) {
                 // do nothing, if ajax request but not related to formhybrid
                 // otherwise a new submission will be generated and validation will fail
                 if ($this->hasDatabaseTable()) {
                     $this->setDefaults($GLOBALS['TL_DCA'][$this->strTable]);
                     // set defaults again, as they might has been overwritten within loadDC/modifyDC
                     $this->setSubmission();
                     $this->save();
                     // initially try to save record, as ajax requests for example require entity model
                 } elseif ($this->hasDatabaseTable() && !$this->hasNoEntity()) {
                     $this->invalid = true;
                     StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid']['messages']['error']['invalidId'], $this->objModule->id, 'alert alert-danger');
                 }
             }
         }
     } else {
         if (!$this->hasDatabaseTable() || $this->hasNoEntity()) {
             $this->setSubmission();
         }
     }
     if ($this->viewMode == FORMHYBRID_VIEW_MODE_READONLY) {
         $this->strTemplate = $this->readonlyTemplate;
         $this->setDoNotSubmit(true);
     }
 }
开发者ID:heimrichhannot,项目名称:contao-formhybrid,代码行数:42,代码来源:DC_Hybrid.php

示例13: createLegacy

 /**
  * Create legacy model
  *
  * @param ModelInterface $model
  * @return \Model
  * @throws
  */
 public static function createLegacy(ModelInterface $model)
 {
     $class = \Model::getClassFromTable($model->getProviderName());
     if (!class_exists($class)) {
         throw new \RuntimeException(sprintf('No model class found for "%s"', $model->getProviderName()));
     }
     /** @var \Model $legacy */
     $legacy = new $class();
     $legacy->setRow($model->getPropertiesAsArray());
     return $legacy;
 }
开发者ID:netzmacht,项目名称:contao-dcatools,代码行数:18,代码来源:ModelFactory.php

示例14: compile

 protected function compile()
 {
     $this->Template->headline = $this->headline;
     $this->Template->hl = $this->hl;
     $this->Template->wrapperClass = $this->strWrapperClass;
     $this->Template->wrapperId = $this->strWrapperId;
     $this->strFormId = $this->formHybridDataContainer . '_' . $this->id;
     $strAction = $this->defaultAction ?: \Input::get('act');
     $this->arrEditable = deserialize($this->formHybridEditable, true);
     $this->strToken = $this->strToken ?: \Input::get('token');
     // Do not change this order (see #6191)
     $this->Template->style = !empty($this->arrStyle) ? implode(' ', $this->arrStyle) : '';
     $this->Template->class = trim('mod_' . $this->type . ' ' . $this->cssID[1]);
     $this->Template->cssID = $this->cssID[0] != '' ? ' id="' . $this->cssID[0] . '"' : '';
     $this->Template->inColumn = $this->strColumn;
     if ($this->Template->headline == '') {
         $this->Template->headline = $this->headline;
     }
     if ($this->Template->hl == '') {
         $this->Template->hl = $this->hl;
     }
     if (!empty($this->classes) && is_array($this->classes)) {
         $this->Template->class .= ' ' . implode(' ', $this->classes);
     }
     $this->addDefaultArchive();
     // at first check for the correct request token to be set
     if (!$this->deactivateTokens && !\RequestToken::validate($this->strToken)) {
         if (!$this->blnSilentMode) {
             StatusMessage::addError(sprintf($GLOBALS['TL_LANG']['frontendedit']['requestTokenExpired'], Url::replaceParameterInUri(Url::getUrl(), 'token', \RequestToken::get())), $this->id, 'requestTokenExpired');
         }
         return;
     }
     if ($this->formHybridAllowIdAsGetParameter) {
         $intId = \Input::get($this->formHybridIdGetParameter);
         if (is_numeric($intId)) {
             $this->intId = $intId;
         }
     }
     $strItemClass = \Model::getClassFromTable($this->formHybridDataContainer);
     // get id from share
     if ($strShare = \Input::get('share')) {
         if (($objItem = $strItemClass::findByShareToken($strShare)) !== null && !FormHybridList::shareTokenExpiredOrEmpty($objItem, time())) {
             $this->intId = $objItem->id;
         }
     }
     if (!$this->intId) {
         if (isset($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior']) && is_array($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior'])) {
             foreach ($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior'] as $arrCallback) {
                 $this->import($arrCallback[0]);
                 if ($this->{$arrCallback}[0]->{$arrCallback}[1]($this) === false) {
                     return;
                 }
             }
         }
         if ($this->noIdBehavior == 'error') {
             if (!$this->blnSilentMode) {
                 StatusMessage::addError($GLOBALS['TL_LANG']['frontendedit']['noIdFound'], $this->id, 'noidfound');
             }
             return;
         } elseif ($this->noIdBehavior == 'redirect' || $this->noIdBehavior == 'create_until') {
             $arrConditions = deserialize($this->existanceConditions, true);
             if ($this->existanceConditions && !empty($arrConditions)) {
                 $arrColumns = array();
                 $arrValues = array();
                 foreach ($arrConditions as $arrCondition) {
                     if (!$arrCondition['field']) {
                         continue;
                     }
                     $arrColumns[] = $arrCondition['field'] . '=?';
                     $arrValues[] = $this->replaceInsertTags($arrCondition['value']);
                 }
                 if (!empty($arrColumns) && ($objItem = $strItemClass::findOneBy($arrColumns, $arrValues)) !== null) {
                     $this->intId = $objItem->id;
                 }
             }
         }
         if (!$this->intId) {
             if ($this->noIdBehavior == 'redirect') {
                 if (!$this->blnSilentMode) {
                     StatusMessage::addError($GLOBALS['TL_LANG']['frontendedit']['noIdFound'], $this->id, 'noidfound');
                 }
                 return;
             } else {
                 $strFormId = FormHelper::getFormId($this->formHybridDataContainer, $this->id);
                 // get id from FormSession
                 if ($_POST) {
                     if ($intId = FormSession::getSubmissionId($strFormId)) {
                         $this->intId = $intId;
                     }
                 }
                 if (!$this->intId) {
                     // if no id is given a new instance is initiated
                     $objConfiguration = new FormConfiguration($this->arrData);
                     // ajax handling, required in this manor, as we have no real ajax controller in contao and ajax request not related to this module
                     // might trigger this module beforhand and new submission will be created after the submission was transfered to the user and id wont match any more
                     if (Ajax::isRelated(Form::FORMHYBRID_NAME) !== null) {
                         if ($intId = FormSession::getSubmissionId($strFormId)) {
                             $this->intId = $intId;
                         } else {
                             $objConfiguration->forceCreate = true;
//.........这里部分代码省略.........
开发者ID:heimrichhannot,项目名称:contao-frontendedit,代码行数:101,代码来源:ModuleReader.php

示例15: createFromDbResult

 /**
  * Create a new collection from a database result
  *
  * @param \Database\Result $objResult The database result object
  * @param string           $strTable  The table name
  *
  * @return static The model collection
  */
 public static function createFromDbResult(\Database\Result $objResult, $strTable)
 {
     $arrModels = array();
     $strClass = \Model::getClassFromTable($strTable);
     while ($objResult->next()) {
         /** @var \Model $strClass */
         $objModel = \Model\Registry::getInstance()->fetch($strTable, $objResult->{$strClass::getPk()});
         if ($objModel !== null) {
             $objModel->mergeRow($objResult->row());
             $arrModels[] = $objModel;
         } else {
             $arrModels[] = new $strClass($objResult);
         }
     }
     return new static($arrModels, $strTable);
 }
开发者ID:StephenGWills,项目名称:sample-contao-app,代码行数:24,代码来源:Collection.php


注:本文中的Model::getClassFromTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。