本文整理汇总了PHP中ActivityModel::update方法的典型用法代码示例。如果您正苦于以下问题:PHP ActivityModel::update方法的具体用法?PHP ActivityModel::update怎么用?PHP ActivityModel::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActivityModel
的用法示例。
在下文中一共展示了ActivityModel::update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
public static function update($id, $data)
{
if (isset($data['actname']) && empty($data['actname'])) {
return print json_encode(array('success' => false, 'status' => 400, 'msg' => 'Activity Name is required'));
}
if (isset($data['actstartdate']) && empty($data['actstartdate'])) {
return print json_encode(array('success' => false, 'status' => 400, 'msg' => 'Start date is required'));
}
if (isset($data['actenddate']) && empty($data['actenddate'])) {
return print json_encode(array('success' => false, 'status' => 400, 'msg' => 'End date is required'));
}
ActivityModel::update($id, $data);
}
示例2: chooseactivityAction
public function chooseactivityAction()
{
$activityid = $this->getRequest()->getParam('activityid', '0');
$account = $_COOKIE["account"];
$uid = $_SESSION["userinfo"][0];
if ($uid == null) {
$this->view->info = '未登录';
$this->_forward('result3', 'globals');
return;
}
$usertable = new UserModel();
$db1 = $usertable->getAdapter();
$table = new User_ActivityModel();
$db2 = $table->getAdapter();
$activitytable = new ActivityModel();
$db3 = $activitytable->getAdapter();
//查找当前用户ID
$result = $usertable->fetchRow($db1->quoteInto('email = ?', $account))->toArray();
$uid = $result['id'];
//检查是否该用户参加过此活动
$where = $db2->quoteInto('userid = ? ', $uid) . $db2->quoteInto('AND activityid = ?', $activityid);
$flag0 = count($table->fetchAll($where)->toArray());
if ($flag0 != 0) {
$this->view->info = '已参加';
$this->_forward('result2', 'globals');
return;
}
//添加一条记录
$set = array('userid' => $uid, 'activityid' => $activityid);
$flag1 = $table->insert($set);
//活动列表更新nums
$nums = $activitytable->find($activityid)->toArray()[0]['nums'];
$nums++;
$numsset = array('nums' => $nums);
$where = $db3->quoteInto('id = ?', $activityid);
$flag2 = $activitytable->update($numsset, $where);
/* echo $flag1;
echo $flag2;
exit(); */
//判断是否成功
if ($flag1 > 0 && $flag2 > 0) {
$this->view->info = 'success';
} else {
$this->view->info = 'fail';
}
$this->_forward('result2', 'globals');
}
示例3: updateActivitiesArray
public static function updateActivitiesArray($activities, $initID = null)
{
if (!$initID || !$activities || !is_array($activities) || !is_numeric($initID)) {
throw new Exception('Invalid data structure');
}
try {
$db = Globals::getDBConn();
$db->beginTransaction();
foreach ($activities as $actGroupKey => $activityGroup) {
if (isset($activityGroup['title']) && strlen($activityGroup['title']) > 0 && isset($activityGroup['id']) && isset($activityGroup['desc']) && isset($activityGroup['required']) && isset($activityGroup['allowMulti'])) {
$actGroupData = array('title' => $activityGroup['title'], 'desc' => $activityGroup['desc'], 'rank' => $actGroupKey, 'required' => (int) $activityGroup['required'], 'allowMulti' => (int) $activityGroup['allowMulti']);
if (is_numeric($activityGroup['id'])) {
$activityGroupObj = new ActivityGroupModel($activityGroup['id']);
if (!$activityGroupObj) {
throw new Exception('Failed to retrieve activity group');
}
$activityGroupObj->update($actGroupData);
$activityGroupID = $activityGroupObj->getMetadata('id');
} else {
if ('new-act-group' === $activityGroup['id']) {
$actGroupData['init'] = $initID;
$activityGroupID = ActivityGroupModel::create($actGroupData);
if (false === $activityGroupID) {
throw new Exception('Failed to create activity group');
}
} else {
throw new Exception('Invalid activity group ID');
}
}
foreach ($activityGroup['activities'] as $actKey => $activity) {
if (isset($activity['title']) && strlen($activity['title']) > 0 && isset($activity['id']) && isset($activity['desc']) && isset($activity['enabled'])) {
$actData = array('title' => $activity['title'], 'desc' => $activity['desc'], 'enabled' => (int) $activity['enabled'], 'group' => $activityGroupID, 'rank' => $actKey);
if (is_numeric($activity['id'])) {
$activityObj = new ActivityModel($activity['id']);
if (!$activityObj) {
throw new Exception('Failed to retrieve activity');
}
$activityObj->update($actData);
} else {
if ('new-act' === $activity['id']) {
//$actData['init'] = $initID;
$activityID = self::create($actData);
if (false === $activityID) {
throw new Exception('Failed to create activity');
}
} else {
throw new Exception('Invalid activity ID');
}
}
} else {
throw new Exception('Missing required activity fields (title, ID, enabled, or desc)');
}
}
} else {
throw new Exception('Missing required activity group fields (title, ID, required, allowMulti, or desc)');
}
}
$db->commit();
} catch (Exception $e) {
$db->rollBack();
throw $e;
}
return true;
}