iPédiatre
 Tout Classes Fichiers Fonctions Variables
ipsort.php
Aller à la documentation de ce fichier.
1 <?php
2 // ipediatre::sort
4 {
5  public static function article($args)
6  {
7  $var = filter_var($args[0], FILTER_VALIDATE_INT);
8 
9  if( $var === false)
10  throw new InvalidArgumentException("Bad argument to fetch articles");
11 
12  echo ezjscAjaxContent::nodeEncode(eZContentObjectTreeNode::fetch($var), array('dataMap'=>array('name')));
13 
14  }
15 
16  public static function articles($args)
17  {
18  $arg = filter_var($args[0], FILTER_VALIDATE_INT);
19 
20  if( $arg === false)
21  throw new InvalidArgumentException("Bad argument to fetch articles");
22 
23  $node = eZUser::fetch($arg)->contentObject()->mainNode();
24 
25  $result = array();
26 
27  foreach ($node->children() as $child)
28  {
29  $object = $child->object();
30  $object_id = $object->attribute('id');
31 
32  $result[] = array(
33  'id' => $object->attribute('id'),
34  'name' => $object->attribute('name'),
35  'is_published' => (bool)eZFunctionHandler::execute('ipediatre','is_published', array('object_id'=>$object_id, 'user_id'=>$arg)),
36  'is_new' => (bool)eZFunctionHandler::execute('ipediatre','is_new', array('object_id'=>$object_id, 'user_id'=>$arg)),
37  'is_mine' => (bool)eZFunctionHandler::execute('ipediatre','is_mine', array('object_id'=>$object_id, 'user_id'=>$arg)),
38  );
39  }
40 
41  return json_encode($result);
42 
43  }
44 
45  public static function sort($args)
46  {
47  $http = eZHTTPTool::instance();
48  if( !$http->hasPostVariable( 'node' ) )
49  {
50  eZDebug::writeError('Fonction de tri par Ajax appelée mais il manquait la liste de noeuds');
51  return;
52  }
53  if( !$http->hasPostVariable( 'user_id' ) )
54  {
55  eZDebug::writeError('Fonction de tri par Ajax appelée mais il manquait le user_id');
56  return;
57  }
58 
59  $UserID = $http->postVariable('user_id');
60  $nodes = $http->postVariable('node');
61  $priorityArray = array_keys($nodes);
62  $priorityIDArray = array_values($nodes);
63 
64  eZContentOperationCollection::updatePriority(eZContentObject::fetch($UserID)->mainNodeID(), $priorityArray, $priorityIDArray);
65  eZContentCacheManager::clearContentCacheIfNeeded( $UserID );
66 
67  return "ok";
68  }
69 
70  public static function publish($args) {
71 
72  $ObjectID = $args[0];
73  $article = eZContentObject::fetch($ObjectID);
74  $UserNodeID = eZUser::currentUser()->contentObject()->mainNodeID();
75  $UserNode = eZUser::currentUser()->contentObject()->mainNode();
76  $NodeID = $article->mainNodeID();
77  $ParentNodeID = $article->mainParentNodeID();
78  $children = $UserNode->children();
79 
80  // On décale les priorités de 1 sur le droite pour laisser la place au nouveau noeud (de priorité 0)
81  $priorityArray = array_map(function($n){return $n+1;}, array_keys($children));
82  $priorityIDArray = array_map(function($n){return $n->attribute('node_id');}, array_values($children));
83  eZContentOperationCollection::updatePriority($UserNodeID, $priorityArray, $priorityIDArray);
84  eZContentCacheManager::clearContentCacheIfNeeded(eZUser::currentUser()->contentObject()->attribute('id') );
85 
86  // Si l'utilisateur est le propriétaire on ne peut pas supprimer le noeud, on le cache plutôt
87  if ($ParentNodeID == $UserNodeID && $article->mainNode()->attribute('is_hidden')) {
88  $article->mainNode()->setAttribute('priority', 0); // on simule la création d'un nouveau noeud (priorité = 0)
89  eZContentOperationCollection::changeHideStatus( $NodeID );
90  eZDebug::writeNotice("l'article $ObjectID a été publié par son propriétaire",'ajax');
91  } else {
92  eZContentOperationCollection::addAssignment( $NodeID, $ObjectID, array($UserNodeID) );
93  eZDebug::writeNotice("l'article $ObjectID a été publié par un pédiatre",'ajax');
94  }
95 
96  return "ok";
97  }
98 
99  public static function unpublish($args) {
100 
101  $ObjectID = $args[0];
102  $UserNodeID = eZUser::currentUser()->contentObject()->mainNodeID();
103  $article = eZContentObject::fetch( $ObjectID );
104  $nodes = $article->assignedNodes();
105  $ParentNodeID = $article->mainParentNodeID();
106  $NodeID = $article->mainNodeID();
107 
108  if ($ParentNodeID == $UserNodeID ) {
109 
110  eZContentOperationCollection::changeHideStatus( $NodeID );
111  eZDebug::writeNotice("l'article $ObjectID a été dépublié par son propriétaire");
112 
113  } else {
114 
115  $to_remove_nodes = array_filter( $nodes, function($node) use($UserNodeID){ return ( $node->attribute('parent_node_id') == $UserNodeID ); } );
116  $to_remove_nodes_id = array_map( function($node) { return (int) $node->attribute('node_id'); }, $to_remove_nodes );
117 
118  eZContentOperationCollection::removeNodes( $to_remove_nodes_id );
119  eZDebug::writeNotice("l'article $ObjectID a été dépublié par un pédiatre");
120 
121  }
122  return "ok";
123  }
124 
125  public static function storeInSession($args)
126  {
127  list($name, $value) = $args;
128  eZPreferences::storeInSession($name, $value);
129  }
130 
131  public static function storedSessionValue($args)
132  {
133  list($name) = $args;
134  return eZPreferences::storedSessionValue($name, $value);
135  }
136 
137  public static function myecho($args) {
138  return json_encode($args);
139  }
140 
141  public static function send($args)
142  {
143  $mail = new ezcMail();
144  $http = eZHTTPTool::instance();
145  $ini = eZINI::instance();
146  $user = eZUser::currentUser();
147  $to = new ezcMailAddress( 'cc@synap.fr', 'Charles-Édouard', 'utf-8');
148  $mail->from = new ezcMailAddress( $user->attribute('email'), $user->contentObject()->name(), 'utf-8' );
149  $mail->subject = $subject;
150 // $mail->body = new ezcMailText($http->postVariable('content').ezpI18n::tr("\n-- \nThis email has been sent through the iPediatrician contact form"),'utf-8'); ; //$
151  $mail->body = new ezcMailText(ezpI18n::tr("\n-- \nThis email has been sent through the iPediatrician contact form"),'utf-8'); ; //$
152  $mail->to = array( $to );
153  $mail->subjectCharset = 'utf-8';
154 
155  $transport = new iPMailTransport($ini);
156 
157  try {
158  $transport->send($mail);
159  $tpl->setVariable( 'success', true );
160  eZDebug::writeDebug("Le module de contact a tenté d'envoyer un email à `{$to}`");
161  }
162  catch(Exception $e)
163  {
164  eZDebug::writeError("Le module de contact a tenté d'envoyer un email à `{$to}` mais l'envoi a échoué: ".$e->getMessage());
165  }
166  }
167 }