All Data Structures Functions Variables Pages
DefaultController.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
43  public function actionInlineCreateSave($redirectUrl = null)
44  {
45  $socialItem = new SocialItem();
46  $socialItem->setScenario('createPost');
47  if (isset($_POST['ajax']) && $_POST['ajax'] === 'social-item-inline-edit-form')
48  {
49  $this->actionInlineEditValidate($socialItem, 'SocialItem');
50  }
51  $_POST['SocialItem']['explicitReadWriteModelPermissions']['type'] = ExplicitReadWriteModelPermissionsUtil::
52  MIXED_TYPE_EVERYONE_GROUP;
53  $this->attemptToSaveModelFromPost($socialItem, $redirectUrl);
54  }
55 
56  public function actionPostGameNotificationToProfile($content)
57  {
58  $socialItem = new SocialItem();
59  $socialItem->description = $content;
60  $socialItem->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME),
61  Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
62  $saved = $socialItem->save();
63  if (!$saved)
64  {
65  throw new FailedToSaveModelException();
66  }
67  }
68 
69  protected function actionInlineEditValidate($model)
70  {
71  $postData = PostUtil::getData();
72  $postFormData = ArrayUtil::getArrayValue($postData, get_class($model));
73  $sanitizedPostData = PostUtil::
74  sanitizePostByDesignerTypeForSavingModel($model, $postFormData);
75  $model->setAttributes($sanitizedPostData);
76  $model->validate();
78  echo CJSON::encode($errorData);
79  Yii::app()->end(0, false);
80  }
81 
82  protected static function getZurmoControllerUtil()
83  {
84  $getData = GetUtil::getData();
85  $relatedUserId = ArrayUtil::getArrayValue($getData, 'relatedUserId');
86  if ($relatedUserId == null)
87  {
88  $relatedUser = null;
89  }
90  else
91  {
92  $relatedUser = User::getById((int)$relatedUserId);
93  }
94  return new SocialItemZurmoControllerUtil($relatedUser);
95  }
96 
100  public function actionInlineCreateCommentFromAjax($id, $uniquePageId)
101  {
102  $comment = new Comment();
103  $redirectUrl = Yii::app()->createUrl('/socialItems/default/inlineCreateCommentFromAjax',
104  array('id' => $id,
105  'uniquePageId' => $uniquePageId));
106  $urlParameters = array('uniquePageId' => $uniquePageId,
107  'relatedModelId' => (int)$id,
108  'relatedModelClassName' => 'SocialItem',
109  'relatedModelRelationName' => 'comments',
110  'redirectUrl' => $redirectUrl); //After save, the url to go to.
111  $socialItem = SocialItem::getById((int)$id);
112  $uniquePageId = SocialItemsUtil::makeUniquePageIdByModel($socialItem);
113  $content = ZurmoHtml::tag('span', array(),
114  ZurmoHtml::link(Zurmo::t('CommentsModule', 'Comment'), '#',
115  array('class' => 'show-create-comment')));
116  $inlineView = new CommentForSocialItemInlineEditView($comment, 'default', 'comments', 'inlineCreateSave',
117  $urlParameters, $uniquePageId, $socialItem->id);
118  $view = new AjaxPageView($inlineView);
119  echo $content . ZurmoHtml::tag('div', array('style' => 'display:none;'), $view->render());
120  }
121 
122  public function actionDeleteViaAjax($id)
123  {
124  $socialItem = SocialItem::getById(intval($id));
125  if (!$socialItem->canUserDelete(Yii::app()->user->userModel) &&
126  $socialItem->owner->id != Yii::app()->user->userModel->id &&
127  $socialItem->toUser->id != Yii::app()->user->userModel->id)
128  {
129  $messageView = new AccessFailureAjaxView();
130  $view = new AjaxPageView($messageView);
131  echo $view->render();
132  Yii::app()->end(0, false);
133  }
134  $deleted = $socialItem->delete();
135  if (!$deleted)
136  {
137  throw new FailedToDeleteModelException();
138  }
139  }
140  }
141 ?>
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
static makeErrorsDataAndResolveForOwnedModelAttributes($model)
attemptToSaveModelFromPost($model, $redirectUrlParams=null, $redirect=true, $returnOnValidate=false)
static getByName($name)
Definition: Group.php:57
actionInlineCreateCommentFromAjax($id, $uniquePageId)
static getById($id, $modelClassName=null)
actionInlineCreateSave($redirectUrl=null)
static sanitizePostByDesignerTypeForSavingModel($model, $postData)
Definition: PostUtil.php:94
Generated on Sun Feb 16 2020 07:10:21