public function _action($action) { //$app = application::getInstance(); $modelId = intval($action); $class = get_class($this); $cl = strlen($class); $lc = 'ListController'; $l = strlen($lc); if ($this->_model === null) { if (substr($class, $cl - $l, $l) == $lc) { $this->_model = substr($class, 0, $cl - $l); } if ($this->_model === null || !class_exists($this->_model)) { throw new Exception('setup $_model in ' . get_class($this)); } } $model = $this->_model; if ($this->_subController === null) { $this->_subController = $model . 'Controller'; if (!class_exists($this->_subController)) { throw new Exception('setup $_subController in ' . get_class($this)); } } $subController = $this->_subController; $items = modelCollection::getInstance($model); $id = $this->_id; $item = $items->select()->where("{$items->{$id}} = '{$modelId}'")->fetch(); if ($item) { $this->onValidItem($modelId, $item); $this->runController($subController, array($model => $item)); } else { $this->notFound(); } }
/** * @return boolean whether authentication succeeds */ public function authenticate() { $users = user::getCollection(); //modelCollection::getInstance('registeredUser'); $emails = modelCollection::getInstance('userEmail'); $result = $users->select($emails, $emails->email->is($this->_email))->fetch(); if (!$result) { throw new authException('Email not registered', authException::ERROR_EMAIL_INVALID); } list($user, $userEmail) = $result; $this->_isRegistered = true; if (!$user->password->equals($this->_password)) { throw new authException('Invalid password ("' . $user->password->getInternalValue() . '" != "' . $user->password->getHash($this->_password) . '")', authException::ERROR_PASSWORD_INVALID); } $this->_user = $user; $this->_identityModels['email'][$this->_email] = $userEmail; }
/** * @return boolean whether authentication succeeds */ public function authenticate() { $users = user::getCollection(); //modelCollection::getInstance('registeredUser'); $logins = modelCollection::getInstance('userLogin'); $result = $users->select($logins, $logins->login->is($this->_login))->fetch(); if (!$result) { throw new authException('Login not registered', authException::ERROR_USERNAME_INVALID); } list($user, $userLogin) = $result; $this->_isRegistered = true; if (!$user->password->equals($this->_password)) { throw new authException('Invalid password', authException::ERROR_PASSWORD_INVALID); } $this->_user = $user; $this->_identityModels['login'][$this->_login] = $userLogin; }
/** * @return boolean whether authentication succeeds */ public function authenticate() { $openid = $this->_openidIdentity; if (!$this->authenticateOpenId($openid)) { throw new authException('Invalid OpenID'); } $openid = $this->_openidIdentity; $users = user::getCollection(); //modelCollection::getInstance('registeredUser'); $openids = modelCollection::getInstance('userOpenid'); $result = $users->select($openids, $openids->openid->is($this->_openidIdentity))->fetch(); if (!$result) { // throw new authException('OpenID "'.$this->_openidIdentity.'" not registered', authException::ERROR_NOT_REGISTERED); // autocreate: $user = new registeredUser(); //$user->save(); $userOpenid = new userOpenid(); $userOpenid->userId = $user->id; $userOpenid->openid = $this->_openidIdentity; //$userOpenid->save(); } else { list($user, $userOpenid) = $result; $this->_isRegistered = true; } /* if (!$user->password->equals($this->_password)){ throw new authException('Invalid password', authException::ERROR_PASSWORD_INVALID); } */ $this->_user = $user; $this->_identityModels['openid'][$this->_openidIdentity] = $userOpenid; if (isset($this->_attributes['contact/email'])) { $email = $this->_attributes['contact/email']; if (!isset($this->_identityModels['email'][$email])) { $userEmail = new userEmail(); $userEmail->email = $email; $userEmail->userId = $user->id; $this->_identityModels['email'][$email] = $userEmail; } } //var_dump($this->_attributes); return true; }
/** * Create collections if not exists */ protected function _createCollection() { //if ($this->_autoRepair){ /*throw new Exception( 'Trying to _createCollection()' );*/ $created = false; //echo 'Create collection()'."\r\n"; $models = $this->getStorage()->getModels(); foreach ($models as $model) { $collection = modelCollection::getInstance($model); /** @var modelCollection $collection */ if (!$collection->exists()) { //echo $model.' collection not exists'."\r\n"; //$this->disableAutoRepair(); //$this->disableServiceMode(); //echo $collection->getCreateSql(); /*throw new Exception( 'Trying to create table '.$collection->getTableName().' SQL:'.$collection->getCreateSql() );*/ if ($collection->internalQuery($collection->getCreateSql())) { $created = true; } //$this->enableServiceMode(); //$this->enableAutoRepair(); } else { //echo $model.' collection exists'."\r\n"; } } /*throw new Exception( 'Trying to _createCollection() - end' );*/ return $created; //} //return false; }
public static function getCollection() { return modelCollection::getInstance(self::$_model); }
public static function getIndirectTablesJoins($sourceTable, $targetTable, $joinTypes, $joinWhere) { $keys =& storageRegistry::getInstance()->foreignKeys; $sourceClass = self::getTableModel($sourceTable); $targetClass = self::getTableModel($targetTable); $joins = array(); $joinedTables = array(); //echo 'Connecting from '.$sourceClass.' to '.$targetClass.'<br />'; foreach ($keys[$sourceClass] as $foreignClass => $options) { if ($foreignClass == $targetClass) { if (!is_array($options)) { $viaClass = $options; //echo 'Connecting via '.$viaClass.'<br />'; $viaTable = modelCollection::getInstance($viaClass); $subJoins = self::getIndirectTablesJoins($sourceTable, $viaTable, $joinTypes, $joinWhere); if ($subJoins !== false) { foreach ($subJoins as $uid => $joinString) { $joins[$uid] = $joinString; } } $subJoins = self::getIndirectTablesJoins($viaTable, $targetTable, $joinTypes, $joinWhere); if ($subJoins !== false) { foreach ($subJoins as $uid => $joinString) { $joins[$uid] = $joinString; } } return $joins; } else { // FIXED JOIN TYPE & ON() SELECTION $joinType = isset($joinTypes[$targetTable->getUniqueId()]) ? $joinTypes[$targetTable->getUniqueId()] : 'INNER'; $joinOn = $sourceTable->getJoinOn($targetTable); if ($joinOn === null) { $joinOn = $targetTable->getJoinOn($sourceTable); if ($joinOn === null) { $joinOn = ''; } } list($sourcePropertyName, $targetPropertyName) = $options; $joinString = " " . $joinType . " JOIN {$targetTable->getTableName()} AS {$targetTable} ON ({$sourceTable->{$sourcePropertyName}} = {$targetTable->{$targetPropertyName}}"; if (isset($joinWhere[$targetTable->getUniqueId()])) { // apply filters $joinString .= " AND " . implode(" AND ", $joinWhere[$targetTable->getUniqueId()]); } if (strlen($joinOn)) { $joinString .= " AND " . $joinOn; } $joinString .= ")"; //$joins[$sourceTable->getUniqueId()] = true; $joins[$targetTable->getUniqueId()] = $joinString; //echo 'Connecting via DIRECT<br />'; if ($joinString !== false) { return $joins; } //array($joinedTables, $joinString); } } } //var_dump($keys[$sourceClass]); //throw new Exception('Connecting via FALSE'); return false; }
public static function getCollection($modelName) { return modelCollection::getInstance($modelName); }
public function getCommentsCollection() { return modelCollection::getInstance($this->_getCommentClass()); }
/** * @return modelCollection */ public static function &getCollection() { if (!function_exists('get_called_class')) { require_once dirname(__FILE__) . '/../common/compat/get_called_class.php'; // PHP 5 >= 5.2.4 } //echo get_called_class(); //var_dump(debug_backtrace()); return modelCollection::getInstance(get_called_class()); // PHP 5 >= 5.3.0 }