本文整理汇总了PHP中BaseObject::isNew方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseObject::isNew方法的具体用法?PHP BaseObject::isNew怎么用?PHP BaseObject::isNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseObject
的用法示例。
在下文中一共展示了BaseObject::isNew方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: retrieveOrCreateByObject
public static function retrieveOrCreateByObject(BaseObject $object)
{
if ($object->isNew() === true || $object->isModified() === true || $object->isDeleted() === true) {
throw new Exception('You can only approve an object which has already been saved');
}
$columnName = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_column', 'is_approved');
$approvedValue = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_approved_value', true);
$disabledApplications = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_disabled_applications');
// Test if we should crated an approval - is the column value different to out required value?
// If our object is already approved then we can delete other
$columnGetter = 'get' . sfInflector::camelize($columnName);
if ($approvedValue != $object->{$columnGetter}()) {
$c = new Criteria();
$c->add(sfApprovalPeer::APPROVABLE_ID, $object->getPrimaryKey());
$c->add(sfApprovalPeer::APPROVABLE_MODEL, get_class($object));
$approval = sfApprovalPeer::doSelectOne($c);
if (!$approval) {
$approval = new sfApproval();
$approval->setApprovableModel(get_class($object));
$approval->setApprovableId($object->getPrimaryKey());
$approval->setUuid(sfPropelApprovableToolkit::generateUuid());
$approval->save();
}
return $approval;
} else {
sfApprovalPeer::deleteByObject($object);
return null;
}
return $approval;
}
示例2: recommend
/**
* Adds a user recommendation to the object.
*
* @param BaseObject $object
* @param integer $user_id
* @return bool
*/
public function recommend(BaseObject $object, $user_id = null)
{
if (true === $object->isNew()) {
throw new Exception('Comments can only be attached to already saved objects');
}
$sfContext = sfContext::getInstance();
// unregistered user handling (via cookie)
if ($user_id === null) {
/*
$sfContext = sfContext::getInstance();
$cookieName = md5($object->getPrimaryKey().get_class($object));
$cookieValue = 'ok';
if (!$sfContext->getRequest()->getCookie($cookieName) == $cookieValue)
{
$sfContext->getResponse()->setCookie($cookieName, $cookieValue);
return $this->saveRecommendation($object);
}
*/
$sfContext->getLogger()->info('Userid Null, returning false...');
return false;
} else {
$sfContext->getLogger()->info('Userid OK, checking for previous recommendation...');
if (!$this->userRecommendationExists($object, $user_id)) {
$sfContext->getLogger()->info('User has not recommended previously...');
$this->saveUserRecommendation($object, $user_id);
$sfContext->getLogger()->info('User rec saved, updating master rec table...');
return $this->saveRecommendation($object);
}
}
$sfContext->getLogger()->info('Something did not work, returning false...');
return false;
}
示例3: addComment
/**
* Adds a comment to the object. The "comment" param can be an associative
* array (in which each element represents one of the comment properties), or
* an array of associative arrays. In this case, it adds all the comments to
* the object.
*
* @param BaseObject $object
* @param array $comment
*/
public function addComment(BaseObject $object, $comment)
{
if ($object->isNew() === true) {
throw new Exception('Comments can only be attached to already saved objects');
}
if (is_array($comment)) {
if (!isset($comment['text'])) {
foreach ($comment as $onecomment) {
$this->addComment($object, $onecomment);
}
} else {
if (strlen($comment['text']) > 0) {
$comment['text'] = strip_tags($comment['text']);
$comment['created_at'] = time();
if (!isset($comment['namespace'])) {
$comment['namespace'] = '';
}
$comment_object = new sfComment();
$comment_object->fromArray($comment, BasePeer::TYPE_FIELDNAME);
$comment_object->setCommentableId($object->getPrimaryKey());
$comment_object->setCommentableModel(get_class($object));
$comment_object->save();
return $comment_object;
}
}
} elseif (is_string($comment)) {
$this->addComment($object, array('text' => $comment));
} else {
new Exception('A comment must be represented as string or an associative array with a "text" key');
}
}
示例4: getOrCreate
/**
* Retrieves an existing Star object, or return a new empty one
*
* @param BaseObject $object
* @param integer $user_id
* @return Star
**/
protected static function getOrCreate(BaseObject $object, $user_id)
{
if ($object->isNew()) {
throw new sfException('Unsaved objects cannot be starred');
}
$c = new Criteria();
$c->add(StarPeer::STARRED_ID, $object->getPrimaryKey());
$c->add(StarPeer::STARRED_MODEL, get_class($object));
$c->add(StarPeer::USER_ID, $user_id);
$ustar = StarPeer::doSelectOne($c);
return is_null($ustar) ? new Star() : $ustar;
}
示例5: getOrCreate
/**
* Retrieves an existing rating object, or return a new empty one
*
* @param BaseObject $object
* @param mixed $user_id Unique user primary key
* @return sfRating
* @throws sfPropelActAsRatableException
**/
protected static function getOrCreate(BaseObject $object, $user_id = null)
{
if ($object->isNew()) {
throw new sfPropelActAsRatableException('Unsaved objects are not ratable');
}
if (is_null($user_id)) {
return new sfRating();
}
$c = new Criteria();
$c->add(sfRatingPeer::RATABLE_ID, $object->getReferenceKey());
$c->add(sfRatingPeer::RATABLE_MODEL, get_class($object));
$c->add(sfRatingPeer::USER_ID, $user_id);
$user_rating = sfRatingPeer::doSelectOne($c);
return is_null($user_rating) ? new sfRating() : $user_rating;
}
示例6: setLaunching
/**
* launches the Object
*
* @param BaseObject $object
* @param string $namespace
* @throws deppPropelActAsLaunchableException
* @return the number of affected rows
**/
public function setLaunching(BaseObject $object, $namespace = 'home')
{
if ($object->isNew()) {
throw new deppPropelActAsLaunchableException('Unsaved objects are not launchable');
}
if (!is_string($namespace)) {
throw new deppPropelActAsLaunchableException('Namespace can only be a string');
}
$launch = new sfLaunching();
$launch->setObjectModel(get_class($object));
$launch->setObjectId($object->getPrimaryKey());
$launch->setLaunchNamespace($namespace);
$launch->setPriority(sfLaunchingPeer::getNewLaunchPriority($namespace));
$ret = $launch->save();
return $ret;
}
示例7: getApproval
public function getApproval(BaseObject $object)
{
if ($object->isNew() === true || $object->isModified() === true || $object->isDeleted() === true) {
throw new Exception('You can only approve an object which has already been saved');
}
$columnName = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_column', 'is_approved');
$approvedValue = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_approved_value', true);
$disabledApplications = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_disabled_applications');
// Test if we should crated an approval - is the column value different to out required value?
// If our object is already approved then we can delete other
$columnGetter = 'get' . sfInflector::camelize($columnName);
if ($approvedValue != $object->{$columnGetter}()) {
return sfApprovalPeer::retrieveOrCreateByObject($object);
} else {
sfApprovalPeer::deleteByObject($object);
return null;
}
}
示例8: getHash
/**
* Gets hash of current object, or previous specified version
*
* Note: version number is sanity-checked in MeshingBaseObject->getHash()
*
* @param BaseObject $object
* @param integer $version The integer of the version required
*/
public function getHash(BaseObject $object, $version = null)
{
// Return null if not saved, as there is no previous hash to get
if ($object->isNew()) {
return null;
}
$crit = $object->getSelectAllVersionsCriteria();
$vsnColName = constant($object->getVersionablePeerName() . '::VERSION');
if (is_null($version)) {
// To get the current item, save a select by grabbing the latest version row
$crit->addDescendingOrderByColumn($vsnColName);
} else {
$crit->add($vsnColName, $version);
}
// Grabs the latest/only row depending on above criteria
$row = call_user_func(array($object->getVersionablePeerName(), 'doSelectOne'), $crit, $this->con);
// There's a gap between saving a row and its version row. So, if we're in an insert
// and using the Version hash provider, we must catch having no versionable row.
if (!$row) {
return null;
}
return $row->getMeshingHash();
}
示例9: getCounter
/**
* Returns the current value of the counter. If it is the first time that this
* instance of the objects works with its counter, the counter will be
* retrieved from the database. Else, it will use its cached value.
*
* @param BaseObject $object
* @return integer
*/
public function getCounter(BaseObject $object)
{
if ($object->isNew() === true) {
throw new Exception('Counters can only be attached to already saved objects.');
}
if (!isset($object->_counter) || $object->_counter === null) {
$c = new Criteria();
$c->add(sfCounterPeer::COUNTABLE_ID, $object->getPrimaryKey());
$c->add(sfCounterPeer::COUNTABLE_MODEL, get_class($object));
$counter = sfCounterPeer::doSelectOne($c);
if (is_null($counter)) {
$counter = new sfCounter();
$counter->setCountableModel(get_class($object));
$counter->setCountableId($object->getPrimaryKey());
$counter->setCounter(0);
}
if (isset($object->_forced) && $object->_forced) {
$counter->setCounter($object->_counter->getCounter());
}
$object->_counter = $counter;
$object->_forced = false;
}
return $object->_counter->getCounter();
}
示例10: getOrCreate
/**
* Retrieves an existing bookmarking object, or return a new empty one
*
* @param BaseObject $object
* @param mixed $user_id Unique user primary key
* @return sfBookmarking
* @throws deppPropelActAsBookmarkableException
**/
protected static function getOrCreate(BaseObject $object, $user_id)
{
if ($object->isNew()) {
throw new deppPropelActAsBookmarkableException('Unsaved objects are not bookmarkable');
}
if (is_null($user_id)) {
throw new deppPropelActAsBookmarkableException('Anonymous bookmarking not allowed');
}
$c = new Criteria();
$c->add(sfBookmarkingPeer::BOOKMARKABLE_ID, $object->getBookmarkableReferenceKey());
$c->add(sfBookmarkingPeer::BOOKMARKABLE_MODEL, get_class($object));
$c->add(sfBookmarkingPeer::USER_ID, $user_id);
$user_bookmarking = sfBookmarkingPeer::doSelectOne($c);
return is_null($user_bookmarking) ? new sfBookmarking() : $user_bookmarking;
}
开发者ID:valerio-bozzolan,项目名称:openparlamento,代码行数:23,代码来源:deppPropelActAsBookmarkableBehavior.class.php
示例11: setDisplayInSearch
/**
Will set the 'display_in_search' field according to business-logic per object type
// kuser | kshow | entry
// for objects that are search worthy - search_text will hold text from relevant columns depending on the object type
*/
public static function setDisplayInSearch(BaseObject $obj, $parent_obj = null)
{
if ($obj == null) {
return;
}
// update the displayInSearch with the logic above only when the object is new or null
if ($obj->isNew() || $obj->getDisplayInSearch() === null) {
$res = myPartnerUtils::shouldDisplayInSearch($obj->getPartnerId());
$obj_id = $obj->getId();
if ($obj_id && is_numeric($obj_id)) {
self::setRes($res, $obj_id > entry::MINIMUM_ID_TO_DISPLAY);
}
if ($res) {
if ($obj instanceof kuser) {
// if the status is not
self::setRes($res, $obj->getStatus() == KuserStatus::ACTIVE);
} elseif ($obj instanceof kshow) {
self::setRes($res, $obj->getViewPermissions() == kshow::KSHOW_PERMISSION_EVERYONE || $obj->getViewPermissions() == null);
// if the viewPermission changed from kshow::KSHOW_PERMISSION_EVERYONE to something else
// update all entries
if ($res && $obj->isColumnModified(kshowPeer::VIEW_PERMISSIONS)) {
$entries = $obj->getentrys();
foreach ($entries as $entry) {
// run this code for each entry
self::setDisplayInSearch($entry, $obj);
}
}
} elseif ($obj instanceof entry) {
// status=READY , type=MEDIACLIP, view permissions of kshow
self::setRes($res, true);
} else {
throw new Exception("mySearchUtils::setDisplayInSearch - cannot handle objects of type " . get_class($obj));
}
}
$obj->setDisplayInSearch($res);
} else {
// if not new - use the value from the object
$res = $obj->getDisplayInSearch();
}
// echo __METHOD__ . " (" . get_class ( $obj ) . ") res [$res]\n";
$words = "";
$fields_to_use = $obj->getColumnNames();
foreach ($fields_to_use as $field) {
$field_str = $obj->getByName($field, BasePeer::TYPE_FIELDNAME);
// call_user_func ( array ( $obj , $func_name ) );
$words .= " " . $field_str;
}
$extra_invisible_data = null;
if ($obj instanceof kshow) {
$type = $obj->getType();
if (empty($type)) {
$type = kshow::KSHOW_TYPE_OTHER;
}
// add the category to the search
$words .= " _CAT_" . $type;
} elseif ($obj instanceof entry) {
$extra_invisible_data = "_MEDIA_TYPE_" . $obj->getMediaType();
$type = $obj->getType();
// add the SEARCH_ENTRY_TYPE_RC to the words
if ($type == entryType::MIX) {
$extra_invisible_data .= " " . self::SEARCH_ENTRY_TYPE_RC;
}
}
$prepared_text = self::prepareSearchText($words);
$partner_id = $obj->getPartnerId();
// if res == 1 - only for partner , if == 2 - also for kaltura network
$obj->setSearchText(self::addPartner($partner_id, $prepared_text, $res, $extra_invisible_data));
}
示例12: addComment
/**
* Adds a comment to the object.
* The "comment" param can be a string, an associative array
* (in which each element represents one of the comment properties), or
* an array of associative arrays. In this case, it adds all the comments to
* the object.
*
* @param BaseObject $object
* @param array $comment
*/
public function addComment(BaseObject $object, $comment)
{
if ($object->isNew() === true) {
throw new Exception('Comments can only be attached to already saved objects');
}
if (is_array($comment)) {
// array of associative arrays
if (!isset($comment['text'])) {
foreach ($comment as $onecomment) {
$this->addComment($object, $onecomment);
}
} else {
// associative array (with the text key not void)
if (strlen($comment['text']) > 0) {
if (isset($comment['title'])) {
$comment['title'] = strip_tags($comment['title']);
}
if (isset($comment['author_name'])) {
$comment['author_name'] = strip_tags($comment['author_name']);
}
if (isset($comment['author_email'])) {
$comment['author_email'] = strip_tags($comment['author_email']);
}
if (isset($comment['author_website'])) {
$comment['author_website'] = strip_tags($comment['author_website']);
}
// store comment's text, after cleaning it (see app.yml)
$comment['text'] = deppPropelActAsCommentableToolkit::clean($comment['text']);
$comment['created_at'] = time();
if (!isset($comment['namespace'])) {
$comment['namespace'] = null;
}
$comment_object = new sfComment();
$comment_object->fromArray($comment, BasePeer::TYPE_FIELDNAME);
$comment_object->setCommentableId($object->getPrimaryKey());
$comment_object->setCommentableModel(get_class($object));
// when the current user is authenticated, a connection to the user table is made
$user_options = sfConfig::get('app_deppPropelActAsCommentableBehaviorPlugin_user', array());
$curr_user = sfContext::getInstance()->getUser();
if ($user_options['enabled'] && $curr_user->isAuthenticated()) {
if (is_callable(get_class($curr_user), $user_options['cu_id_method'])) {
$comment_object->setAuthorId(call_user_func(array($curr_user, $user_options['cu_id_method'])));
}
if (is_callable(array($user_options['class'] . 'Peer', 'retrieveByPK'))) {
$user = call_user_func($user_options['class'] . 'Peer::retrieveByPk', $comment_object->getAuthorId());
if (array_key_exists('name_method', $user_options) && is_callable(get_class($user), $user_options['name_method'])) {
$comment_object->setAuthorName(call_user_func(array($user, $user_options['name_method'])));
}
if (array_key_exists('email_method', $user_options) && is_callable(get_class($user), $user_options['email_method'])) {
$comment_object->setAuthorEmail(call_user_func(array($user, $user_options['email_method'])));
}
if (array_key_exists('website_method', $user_options) && is_callable(get_class($user), $user_options['website_method'])) {
$comment_object->setAuthorWebsite(call_user_func(array($user, $user_options['website_method'])));
}
}
}
$comment_object->save();
self::_checkAndSaveCountCache($object, $comment['namespace']);
return $comment_object;
}
}
} elseif (is_string($comment)) {
$this->addComment($object, array('text' => $comment));
} else {
new Exception('A comment must be represented as string, an associative array with a "text" key, or an array of associative arrays');
}
}
开发者ID:valerio-bozzolan,项目名称:openparlamento,代码行数:77,代码来源:deppPropelActAsCommentableBehavior.class.php
示例13: getSavedTags
/**
* Retrieves from the database tags that have been atached to the object.
* Once loaded, this saved tags list is cached and updated in memory.
*
* @param BaseObject $object
* @param boolean $force_cache_override if the DB must be read, even when the cache exists
*/
private function getSavedTags(BaseObject $object, $force_cache_override = false)
{
if (!isset($object->_tags) || !$object->_tags->hasNamespace('saved_tags') || $force_cache_override) {
if (true === $object->isNew()) {
self::set_saved_tags($object, array());
return array();
} else {
$c = new Criteria();
$c->add(TaggingPeer::TAGGABLE_ID, $object->getPrimaryKey());
$c->add(TaggingPeer::TAGGABLE_MODEL, get_class($object));
$c->addJoin(TaggingPeer::TAG_ID, TagPeer::ID);
$saved_tags = TagPeer::doSelect($c);
$tags = array();
foreach ($saved_tags as $tag) {
$tags[$tag->getName()] = $tag->getName();
}
self::set_saved_tags($object, $tags);
return $tags;
}
} else {
return self::get_saved_tags($object);
}
}
示例14: preSave
/**
* This hook is called before object is saved.
*
* @param BaseObject $object
*/
public function preSave(BaseObject $object)
{
$this->wasNew = $object->isNew();
// gestisce eccezione generazione passaggi di iter
if ($object instanceof OppAtto && !$object->isNew() && $object->isColumnModified(OppAttoPeer::SUCC)) {
$this->succNews = true;
}
}
开发者ID:valerio-bozzolan,项目名称:openparlamento,代码行数:13,代码来源:deppPropelActAsNewsGeneratorBehavior.class.php
示例15: setDisplayInSearch
/**
Will set the 'display_in_search' field according to business-logic per object type
// kuser | kshow | entry
// for objects that are search worthy - search_text will hold text from relevant columns depending on the object type
*/
public static function setDisplayInSearch(BaseObject $obj, $parent_obj = null)
{
if ($obj == null) {
return;
}
// update the displayInSearch with the logic above only when the object is new or null
if ($obj->isNew() || $obj->getDisplayInSearch() === null) {
$res = myPartnerUtils::shouldDisplayInSearch($obj->getPartnerId());
$obj_id = $obj->getId();
if ($obj_id && is_numeric($obj_id)) {
self::setRes($res, $obj_id > entry::MINIMUM_ID_TO_DISPLAY);
}
if ($res) {
if ($obj instanceof kuser) {
// if the status is not
self::setRes($res, $obj->getStatus() == KuserStatus::ACTIVE);
} elseif ($obj instanceof kshow) {
self::setRes($res, $obj->getViewPermissions() == kshow::KSHOW_PERMISSION_EVERYONE || $obj->getViewPermissions() == null);
// if the viewPermission changed from kshow::KSHOW_PERMISSION_EVERYONE to something else
// update all entries
if ($res && $obj->isColumnModified(kshowPeer::VIEW_PERMISSIONS)) {
$entries = $obj->getentrys();
foreach ($entries as $entry) {
// run this code for each entry
self::setDisplayInSearch($entry, $obj);
}
}
} elseif ($obj instanceof entry) {
// status=READY , type=MEDIACLIP, view permissions of kshow
self::setRes($res, true);
} else {
throw new Exception("mySearchUtils::setDisplayInSearch - cannot handle objects of type " . get_class($obj));
}
}
$obj->setDisplayInSearch($res);
}
}