本文整理汇总了PHP中Author::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Author::exists方法的具体用法?PHP Author::exists怎么用?PHP Author::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Author
的用法示例。
在下文中一共展示了Author::exists方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testExists
public function testExists()
{
$this->assertTrue(Author::exists(1));
$this->assertTrue(Author::exists(array('conditions' => 'author_id=1')));
$this->assertTrue(Author::exists(array('conditions' => array('author_id=? and name=?', 1, 'Tito'))));
$this->assertFalse(Author::exists(9999999));
$this->assertFalse(Author::exists(array('conditions' => 'author_id=999999')));
}
示例2: test_delete
public function test_delete()
{
$author = Author::find(1);
$author->delete();
$this->assert_false(Author::exists(1));
}
示例3: setArticleAuthorsLegacy
/**
* Set authors for an article, uses legacy classes
*
* @param Article $article
* @param \Newscoop\IngestPluginBundle\Entity\Entry $entry
*/
protected function setArticleAuthorsLegacy(\Article $article, \Newscoop\IngestPluginBundle\Entity\Feed\Entry $entry)
{
$authors = $entry->getAuthors();
$order = 0;
if (count($authors) > 0) {
foreach ($authors as $author) {
$name = trim($author['firstname'] . ' ' . $author['lastname']);
$author = new \Author($name);
if (!$author->exists()) {
$author->create();
}
$article->setAuthor($author, $order++);
}
} else {
$name = $entry->getProduct() ?: $entry->getFeed()->getName();
$author = new \Author($name);
if (!$author->exists()) {
$author->create();
}
$article->setAuthor($author);
}
}
示例4: Author
function authors_get()
{
if (!$this->get('search')) {
$this->response(NULL, 400);
}
$authors = new Author();
$authors->like('name', $this->get('search'));
$authors->order_by('name', 'asc');
$authors->limit(5);
$authors->get();
if ($authors->exists()) {
foreach ($authors as $author) {
$authors_array[] = $author->name;
}
$this->response($authors_array, 200);
// 200 being the HTTP response code
} else {
$this->response(array('error' => 'Authors could not be found'), 404);
}
}
示例5: camp_set_author
function camp_set_author(ArticleTypeField $p_sourceField, &$p_errors)
{
$p_errors = array();
$articles = Article::GetArticlesOfType($p_sourceField->getArticleType());
foreach ($articles as $article) {
$articleData = $article->getArticleData();
$authorName = trim($articleData->getFieldValue($p_sourceField->getPrintName()));
if (empty($authorName)) {
continue;
}
$author = new Author($authorName);
if (!$author->exists()) {
if (!$author->create()) {
$p_errors[] = getGS('Unable to create author "$1" for article no. $2 ("$3") of type $4.', $author->getName(), $article->getArticleNumber(), $article->getName(), $article->getType());
continue;
}
}
if (!$article->setAuthorId($author->getId())) {
$p_errors[] = getGS('Error setting the author "$1" for article no. $2 ("$3") of type $4.', $author->getName(), $article->getArticleNumber(), $article->getName(), $article->getType());
continue;
}
}
return count($p_errors);
}
示例6: camp_set_author
function camp_set_author(ArticleTypeField $p_sourceField, &$p_errors)
{
$translator = \Zend_Registry::get('container')->getService('translator');
$p_errors = array();
$articles = Article::GetArticlesOfType($p_sourceField->getArticleType());
foreach ($articles as $article) {
$articleData = $article->getArticleData();
$authorName = trim($articleData->getFieldValue($p_sourceField->getPrintName()));
if (empty($authorName)) {
continue;
}
$author = new Author($authorName);
if (!$author->exists()) {
if (!$author->create()) {
$p_errors[] = $translator->trans('Unable to create author $1 for article no. $2 ($3) of type $4.', array('$1' => $author->getName(), '$2' => $article->getArticleNumber(), '$3' => $article->getName(), '$4' => $article->getType()), 'home');
continue;
}
}
if (!$article->setAuthorId($author->getId())) {
$p_errors[] = $translator->trans('Error setting the author $1 for article no. $2 ($3) of type $4.', array('$1' => $author->getName(), '$2' => $article->getArticleNumber(), '$3' => $article->getName(), '$4' => $article->getType()), 'home');
continue;
}
}
$cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
$cacheService->clearNamespace('authors');
$cacheService->clearNamespace('article');
return count($p_errors);
}
示例7: foreach
$blogService = Zend_Registry::get('container')->getService('blog');
$blogInfo = $blogService->getBlogInfo($g_user);
if (!empty($f_article_author)) {
$em = Zend_Registry::get('container')->getService('em');
$dispatcher = Zend_Registry::get('container')->getService('dispatcher');
$language = $em->getRepository('Newscoop\\Entity\\Language')->findOneById($articleObj->getLanguageId());
$authors = $em->getRepository('Newscoop\\Entity\\ArticleAuthor')->getArticleAuthors($articleObj->getArticleNumber(), $language->getCode())->getArrayResult();
ArticleAuthor::OnArticleLanguageDelete($articleObj->getArticleNumber(), $articleObj->getLanguageId());
foreach ($authors as $author) {
$dispatcher->dispatch("user.set_points", new \Newscoop\EventDispatcher\Events\GenericEvent($this, array('authorId' => $author['fk_author_id'])));
}
$i = 0;
foreach ($f_article_author as $author) {
$authorObj = new Author($author);
$author = trim($author);
if (!$authorObj->exists() && isset($author[0])) {
if ($blogService->isBlogger($g_user)) {
// blogger can't create authors
continue;
}
$authorData = Author::ReadName($author);
$authorObj->create($authorData);
} elseif ($blogService->isBlogger($g_user)) {
// test if using authors from blog
if (!$blogService->isBlogAuthor($authorObj, $blogInfo)) {
continue;
}
}
// Sets the author type selected
$author_type = $f_article_author_type[$i];
$authorObj->setType($author_type);
示例8: GetList
/**
* Returns an article authors list based on the given parameters.
*
* @param array $p_parameters
* An array of ComparisonOperation objects
* @param string $p_order
* An array of columns and directions to order by
* @param integer $p_start
* The record number to start the list
* @param integer $p_limit
* The offset. How many records from $p_start will be retrieved.
* @param integer $p_count
* The total count of the elements; this count is computed without
* applying the start ($p_start) and limit parameters ($p_limit)
*
* @return array $articleAuthorsList
* An array of Author objects
*/
public static function GetList(array $p_parameters, $p_order = null, $p_start = 0, $p_limit = 0, &$p_count, $p_skipCache = false)
{
global $g_ado_db;
if (!$p_skipCache && CampCache::IsEnabled()) {
$paramsArray['parameters'] = serialize($p_parameters);
$paramsArray['order'] = is_null($p_order) ? 'order' : $p_order;
$paramsArray['start'] = $p_start;
$paramsArray['limit'] = $p_limit;
$cacheListObj = new CampCacheList($paramsArray, __METHOD__);
$articleAuthorsList = $cacheListObj->fetchFromCache();
if ($articleAuthorsList !== false && is_array($articleAuthorsList)) {
return $articleAuthorsList;
}
}
$hasArticleNr = false;
$selectClauseObj = new SQLSelectClause();
$countClauseObj = new SQLSelectClause();
// sets the where conditions
foreach ($p_parameters as $param) {
if ($param->getLeftOperand() == 'type') {
$whereCondition = 'fk_type_id ' . $param->getOperator()->getSymbol() . ' (SELECT id FROM ' . AuthorType::TABLE . ' WHERE type="' . str_replace("'", "", $param->getRightOperand()) . '")';
$selectClauseObj->addWhere($whereCondition);
$countClauseObj->addWhere($whereCondition);
}
if ($param->getLeftOperand() == 'id') {
$whereCondition = 'fk_author_id ' . $param->getOperator()->getSymbol() . ' ' . $param->getRightOperand();
$selectClauseObj->addWhere($whereCondition);
$countClauseObj->addWhere($whereCondition);
}
$comparisonOperation = self::ProcessListParameters($param);
if (sizeof($comparisonOperation) < 1) {
break;
}
switch (key($comparisonOperation)) {
case 'fk_article_number':
$whereCondition = 'fk_article_number = ' . $comparisonOperation['fk_article_number'];
$hasArticleNr = true;
break;
case 'fk_language_id':
$whereCondition = '(fk_language_id IS NULL OR ' . 'fk_language_id = ' . $comparisonOperation['fk_language_id'] . ')';
break;
}
$selectClauseObj->addWhere($whereCondition);
$countClauseObj->addWhere($whereCondition);
}
// validates whether article number was given
if ($hasArticleNr === false) {
CampTemplate::singleton()->trigger_error("missed parameter Article Number in statement list_article_authors");
}
// sets the base table ArticleAuthors and the column to be fetched
$tmpArticleAuthor = new ArticleAuthor();
$selectClauseObj->setTable($tmpArticleAuthor->getDbTableName());
$selectClauseObj->addJoin('JOIN ' . Author::TABLE . ' ON fk_author_id = id');
$selectClauseObj->addColumn('fk_author_id');
$selectClauseObj->addColumn('fk_type_id');
$countClauseObj->setTable($tmpArticleAuthor->getDbTableName());
$countClauseObj->addColumn('COUNT(*)');
unset($tmpArticleAuthor);
if (!is_array($p_order)) {
$p_order = array();
}
$order = self::ProcessListOrder($p_order);
// sets the order condition if any
foreach ($order as $orderDesc) {
$orderField = $orderDesc['field'];
$orderDirection = $orderDesc['dir'];
$selectClauseObj->addOrderBy($orderField . ' ' . $orderDirection);
}
// sets the limit
$selectClauseObj->setLimit($p_start, $p_limit);
// builds the query and executes it
$selectQuery = $selectClauseObj->buildQuery();
$authors = $g_ado_db->GetAll($selectQuery);
if (is_array($authors)) {
$countQuery = $countClauseObj->buildQuery();
$p_count = $g_ado_db->GetOne($countQuery);
// builds the array of attachment objects
$authorsList = array();
foreach ($authors as $author) {
$authorObj = new Author($author['fk_author_id'], $author['fk_type_id']);
if ($authorObj->exists()) {
$authorsList[] = $authorObj;
//.........这里部分代码省略.........
示例9: foreach
// Update the first comment if the article title has changed
if ($f_article_title != $articleObj->getTitle()) {
$firstPostId = ArticleComment::GetCommentThreadId($articleObj->getArticleNumber(), $articleObj->getLanguageId());
if ($firstPostId) {
$firstPost = new Phorum_message($firstPostId);
$firstPost->setSubject($f_article_title);
}
}
// Update the article author
if (!empty($f_article_author)) {
ArticleAuthor::OnArticleLanguageDelete($articleObj->getArticleNumber(), $articleObj->getLanguageId());
$i = 0;
foreach ($f_article_author as $author) {
$authorObj = new Author($author);
if (!$authorObj->exists() && strlen(trim($author)) > 0) {
$authorData = Author::ReadName($author);
$authorObj->create($authorData);
}
// Sets the author type selected
$author_type = $f_article_author_type[$i];
$authorObj->setType($author_type);
// Links the author to the article
$articleAuthorObj = new ArticleAuthor($articleObj->getArticleNumber(),
$articleObj->getLanguageId(),
$authorObj->getId(), $author_type);
if (!$articleAuthorObj->exists()) {
$articleAuthorObj->create();
}
$i++;
}
示例10: Author
continue;
}
$articleFields[$field] = true;
$articleTypeObj->setProperty($dbColumn->getName(), (string) $article->{$field});
}
// Updates the article creator and author
$articleObj->setCreatorId($g_user->getUserId());
$isAuthorFromCreator = FALSE;
if (isset($article->author) && !empty($article->author)) {
$authorName = (string) $article->author;
} else {
$authorName = (string) $g_user->getRealName();
$isAuthorFromCreator = TRUE;
}
$authorObj = new Author($authorName);
if (!$authorObj->exists()) {
$authorData = Author::ReadName($authorName);
if ($isAuthorFromCreator) {
$authorData['email'] = $g_user->getEmail();
}
$authorObj->create($authorData);
}
if ($authorObj->exists()) {
$articleObj->setAuthor($authorObj);
$articleFields['author'] = true;
}
// Updates the publish date
$articlePublishDate = (string) $article->publish_date;
$articleObj->setPublishDate($articlePublishDate);
// Updates the article
if (isset($article->keywords) && !empty($article->keywords)) {
示例11: AuthorAlias
if ($del_id_alias > -1) {
$authorAliasObj = new AuthorAlias($del_id_alias);
if ($authorAliasObj->delete()) {
camp_html_add_msg($translator->trans('Author alias removed.', array(), 'users'), 'ok');
} else {
camp_html_add_msg($translator->trans('Cannot remove author alias.', array(), 'users'));
}
}
// Important! Trim spaces and replace multiple ones by space
$first_name = preg_replace('/\\s+/', ' ', trim(Input::Get('first_name')));
$last_name = preg_replace('/\\s+/', ' ', trim(Input::Get('last_name')));
$can_save = false;
if ($id > -1 && strlen($first_name) > 0 && strlen($last_name) > 0) {
$can_save = true;
$tmpAuthor = new Author(implode(' ', array($first_name, $last_name)));
if ($id == 0 && $tmpAuthor->exists()) {
$can_save = false;
camp_html_add_msg($translator->trans('An author with the same full name (combination of first and last name) already exists.', array(), 'users'));
}
}
if ($can_save) {
$author = new Author();
if ($id > 0) {
$author = new Author($id);
$isNewAuthor = false;
} else {
$author->create(array('first_name' => $first_name, 'last_name' => $last_name));
$isNewAuthor = true;
}
$uploadFileSpecified = isset($_FILES['file']) && isset($_FILES['file']['name']) && !empty($_FILES['file']['name']);
$author->setFirstName($first_name);
示例12: BookAuthor
// Drop tables.
$bookAuthor = new BookAuthor();
$bookAuthor->drop()->yesImSure();
$book = new Book();
$book->drop()->yesImSure();
$bookAuthor = new BookAuthor();
$bookAuthor->drop()->yesImSure();
*/
/**
* Auto create database tables. This is just for this demo/sample
*/
$book = new Book();
if (!$book->exists()) {
$book->createTable();
}
$author = new Author();
if (!$author->exists()) {
$author->createTable();
}
$bookAuthor = new BookAuthor();
if (!$bookAuthor->exists()) {
$bookAuthor->createTable();
}
LudoDB::enableLogging();
$request = $_GET['request'];
$data = array();
foreach ($_POST as $key => $value) {
$data[$key] = $value;
}
$handler = new LudoDBRequestHandler();
echo $handler->handle($request, $data);
示例13: setArticleAuthors
/**
* Set article authors
*
* @param Article $article
* @param Newscoop\Entity\Ingest\Feed\Entry $entry
* @return void
*/
private function setArticleAuthors(\Article $article, Entry $entry)
{
$name = $entry->getFeed()->getTitle();
$author = new \Author($name);
if (!$author->exists()) {
$author->create();
}
$article->setAuthor($author);
}