public function testShouldNotInsertDuplicateRecord() { if (!$this->_testsEnabled) { return; } $userModel = new Model_User(); $userId = $userModel->insert(array('email' => self::TEST_EMAIL)); $pwless = new Garp_Auth_Adapter_Passwordless(); $pwless->requestToken(array('email' => self::TEST_EMAIL)); $users = $userModel->fetchAll(); $this->assertEquals(1, count($users)); $this->assertEquals($userId, $users[0]->id); }
public function SelectUser($name, $value = null, $attribs = null, $currentUser = 0) { $u = new Model_User(); $users = $u->fetchAll(null, 'first_name'); $userArray[] = $this->view->getTranslation('Select User'); if ($users->count() > 0) { foreach ($users as $user) { if ($user->id != $currentUser) { $userArray[$user->id] = $user->first_name . ' ' . $user->last_name; } } } return $this->view->formSelect($name, $value, $attribs, $userArray); }
public function fetchAction() { //定义查询方法 $table = new Model_User(); //类的实例化 //定义查询条件 $where = null; $order = "id desc"; //以ID降序排列 $count = 3; //输出3条记录 $offset = 0; //从第1条记录开始 $result_all = $table->fetchAll(); //执行查询语句 $this->view->select = $result_all; }
public function selectUser($name, $value = null, $attribs = null, $currentUser = 0) { $u = new Model_User(); $users = $u->fetchAll(null, 'first_name'); $options[] = $this->view->getTranslation('Select User'); if ($users->count() > 0) { foreach ($users as $user) { if ($user->name != $currentUser) { $options[$user->name] = $user->first_name . ' ' . $user->last_name; } } } $form = new Digitalus_Form(); $select = $form->createElement('select', $name, array('multiOptions' => $options)); if (is_array($value)) { $select->setValue($value); } if (is_array($attribs)) { $select->setAttribs($attribs); } return $select; }
/** * Find friends of logged in user and map to local friends table. * @param Array $config * @return Bool Success */ public function mapFriends(array $config) { $config = $config instanceof Garp_Util_Configuration ? $config : new Garp_Util_Configuration($config); $config->obligate('bindingModel')->obligate('user_id')->setDefault('accessToken', $this->getAccessToken()); if (!$config['accessToken']) { // Find the auth record $authModel = new Model_AuthFacebook(); $authRow = $authModel->fetchRow($authModel->select()->where('user_id = ?', $config['user_id'])); if (!$authRow || !$authRow->access_token) { return false; } // Use the stored access token to create a user session. Me() in the FQL ahead will contain the user's Facebook ID. // Note that the access token is available for a very limited time. Chances are it's not valid anymore. $accessToken = $authRow->access_token; } try { $this->_client->setAccessToken($config['accessToken']); // Find the friends' Facebook UIDs $friends = $this->_client->api(array('method' => 'fql.query', 'query' => 'SELECT uid2 FROM friend WHERE uid1 = me()')); // Find local user records $userModel = new Model_User(); $userTable = $userModel->getName(); $authFbModel = new Model_AuthFacebook(); $authFbTable = $authFbModel->getName(); $fbIds = ''; $friendCount = count($friends); foreach ($friends as $i => $friend) { $fbIds .= $userModel->getAdapter()->quote($friend['uid2']); if ($i < $friendCount - 1) { $fbIds .= ','; } } $friendQuery = $userModel->select()->setIntegrityCheck(false)->from($userTable, array('id'))->join($authFbTable, $authFbTable . '.user_id = ' . $userTable . '.id', array())->where('facebook_uid IN (' . $fbIds . ')')->order($userTable . '.id'); $localUsers = $userModel->fetchAll($friendQuery); $localUserCount = count($localUsers); // Insert new friendships into binding model $bindingModel = new $config['bindingModel'](); $insertSql = 'INSERT IGNORE INTO ' . $bindingModel->getName() . ' (user1_id, user2_id) VALUES '; foreach ($localUsers as $i => $localUser) { $insertSql .= '(' . $localUser->id . ',' . $config['user_id'] . '),'; $insertSql .= '(' . $config['user_id'] . ',' . $localUser->id . ')'; if ($i < $localUserCount - 1) { $insertSql .= ','; } } $result = $bindingModel->getAdapter()->query($insertSql); // Clear cache manually, since the table isn't updated thru conventional paths. Garp_Cache_Manager::purge($bindingModel); return !!$result; } catch (Exception $e) { return false; } }